ASP.NET MVC 5 (Visual Studio 2013 Preview) Change Login Url for [Authorize]

こ雲淡風輕ζ 提交于 2019-12-18 09:08:21

问题


Hey guys I started playing around with the ASP.NET MVC 5 preview and everything has been going fine so far (I can only recommend it).

However, I wonder where I can set the Login-Url for the Built-In [Authorize]-Attribute. I've moved the AccountController to a an area, so the path to the Login action is no longer /Account/Login but MyArea/Account/Login, which is ignored by the [Authorize]-Attribute, which in turn means, that whenever one navigates to a controller or action with the attribute set, one is redirected to the wrong path /Account/Login.


回答1:


Look in web.config for a section like this:

<authentication mode="Forms">
  <forms loginUrl="~/Account/LogOn" timeout="2880" />
</authentication>

Change the loginUrl value to point to your updated login page.




回答2:


When using the new OWIN forms authentication (as opposed to the old ASP.NET forms authentication), this gets set in the Startup class. In the default templates, it's in App_Start/Startup.Auth.cs in the ConfigureAuth method:

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


来源:https://stackoverflow.com/questions/17709020/asp-net-mvc-5-visual-studio-2013-preview-change-login-url-for-authorize

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!