MVC Forms LoginUrl is incorrect

jrummell picture jrummell · May 20, 2011 · Viewed 17.6k times · Source

I have an ASP.NET MVC 3 application with forms authentication. For some reason that I cannot see, the login redirect url is /Account/Login?ReturnUrl=%2fSecure%2fAction instead of /Account/LogOn?ReturnUrl=%2fSecure%2fAction. The difference is subtle, its using /Account/Login instead of /Account/LogOn.

My web.config forms section is correct. Would else could possibly affect the login url??

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

Answer

frennky picture frennky · May 21, 2011

This is a known issue. I had the same problem with my custom authorize attribute. I found the solution somewhere on the net, can't remember where. Just add this to appSettings in your web.config

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

Note: This works with MVC 3, I didn't try it with previous versions.

EDIT: Found it mentioned in release notes, but it seems that they've changed the setting name and forgot to update release notes for RTM version.