I have forms authentication on my MVC site and the default route is set to send users to /home/index. Home/index is excluded from the login requirement, via a Web.config location section. if I type in http://Example/home/index, I go to the home page as expected, but if I just do http://Example, I get redirected to the logon page.
If I turn off authentication and do http://Example, the default route works fine, and I’m sent to the home page.
Why is authentication not respecting the default route? Thanks!
You shouldn’t be using the
<location>element inweb.configto handle authorization in an ASP.NET MVC application as it might clash with your routes. This is used in standard WebForms applications but it is considered bad practice in MVC.The recommended way to handle this is to decorate your controllers/actions with the
[AuthorizeAttribute]. So get rid of alllocationelements in web.config and decorate.