When my team and I upgraded one of the projects from MVC 4 to MVC 5, we encountered an issue where users get redirected to the default log in URL Account/Login which is different to the one specified in the web.config in the authentication section.
<authentication mode="Forms"> <forms loginUrl="~/Account/Security/Login" timeout="2880" /> </authentication>
After a bit of research on the Internet, I found that WebMatrix was what causing this issue. WebMatrix got referenced in the project after the upgrade and that when this issue started. From my research, when WebMatrix is referenced or when WebMatrix.dll is included in the bin directory, it will take over the URL for forms authentication and override the authentication redirect login URL to the default log in URL Account/Login.
There are 3 ways to fix this issue
- This is one of the 2 easiest and quickest ways to fix the problem. Add loginUrl appSetting to the web.config and set its value to the URL that you want to redirect users to
<add key="loginUrl" value="~/Account/Security/Login" >
- Or add the PreserveLoginUrl appSetting and set it to true
<add key="PreserveLoginUrl" value="true" >
- Change your application log in URL to the default log in URL or if WebMatrix is not required, remove all its reference in the project.
Nice article better than i was expecting.you explain very well about how how incorrect log in url redirect in asp.net MVC.
Great write-up!
Really an informative and valuable post about redirect to incorrect url in Asp.net Mvc. I appreciate how beautifully it has been drafted for us to understand. Keep it up!
Really an informative and valuable post.. easy to understand and good for beginner.i learn lot of new things from your post.
Thank you so much for this valuable post.
Great article about ASP.NET MVC. All the points are explained very clearly.
Keep up the good work !!!!