ASP.NET MVC 5(Visual Studio 2013 Preview)更改[授权]的登录URL

Dän*_*änu 3 asp.net-mvc asp.net-mvc-routing asp.net-mvc-5

嘿伙计们我开始玩ASP.NET MVC 5预览,到目前为止一切都很好(我只能推荐它).

但是,我想知道在哪里可以为Built-In [Authorize]-Attribute 设置Login-Url .我搬到了AccountController一个区域,因此该路径登录动作不再/Account/Login,但是MyArea/Account/Login,这是由忽略[Authorize]-Attribute,这反过来又意味着,每当一个导航设置,一个控制器或动作与属性被重定向到错误的路径/Account/Login.

sly*_*ete 16

使用新的OWIN表单身份验证(而不是旧的ASP.NET表单身份验证)时,将在Startup类中设置此身份验证.在默认模板中,它App_Start/Startup.Auth.cs位于ConfigureAuth方法中:

public void ConfigureAuth(IAppBuilder app)
{
   app.UseCookieAuthentication(new CookieAuthenticationOptions
   {
      AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
      LoginPath = new PathString("/Account/Login")
   });
   app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
}
Run Code Online (Sandbox Code Playgroud)


Mat*_*ser 10

寻找web.config像这样的部分:

<authentication mode="Forms">
  <forms loginUrl="~/Account/LogOn" timeout="2880" />
</authentication>
Run Code Online (Sandbox Code Playgroud)

loginUrl值更改为指向更新的登录页面.