I recently upgraded an ASP.Net project from MVC 3 to MVC 5, but wanted to keep our old login mechanism. However, when trying to access a restricted page, I was always redirected to /Account/Login instead of /Account/LogOn. I had already met that problem with MVC 3 and thus I had added the following line in my Web.config file:

    <add key="LoginUrl" value="~/Account/LogOn" />

I researched the matter and added some more stuff in the Web.config file according to the suggestions I found on stackoverflow.com and other forums:

    <add key="PreserveLoginUrl" value="true" />
    <add key="autoFormsAuthentication" value="false" />
    <add key="enableSimpleMembership" value="false" />

and 

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

However, all this did not help. I finally found the culprit by searching for “Login” in my source code. I found this in App_Start\Startup.Auth.cs:

app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
                LoginPath = new PathString("/Account/Login")
            });

I fixed the issue by replacing “/Account/Login” with “/Account/LogOn”.

One thought on “ASP.Net MVC 5 redirecting to /Account/Login

Comments are closed.