MVC5 [授权]重定向到默认路由而不是属性路由

Mic*_*k R 2 asp.net-mvc asp.net-mvc-5

我有以下内容:

    [Route("whitelist")]
    [Authorize(Roles = "Administrator")]
    public ActionResult Whitelist() {
        var vm = new WhitelistViewModel();
        return View(vm);
    }

    [Route("login")]
    [AllowAnonymous]
    public ActionResult Login(string returnUrl) {
        ViewBag.ReturnUrl = returnUrl;
        return View();
    }
Run Code Online (Sandbox Code Playgroud)

但是,当我导航到/whitelist未经身份验证的用户时,我会导航到/ Account/Login,这是无效的.在这种情况下,如何告诉MVC5在重定向时使用属性路由?

Ash*_*Lee 9

App_Start/Startup.Auth.cs,您需要更改重定向的默认登录路径.

LoginPath = new PathString("/login")
Run Code Online (Sandbox Code Playgroud)

原因是由于您添加了属性路由,因此现有路由无效.