Saturday, February 2, 2013

FIX: An MVC website configured for Windows Authentication is trying to redirect to Login page while accessing from IIS

I came across a very strange issue recently. My MVC application was configured to use Windows Authentication, and it was deployed on IIS.
While the website was working very properly when accessed from Development environment, means, it was taking the routes into considerations and was properly redirecting the user to specific routes. However, while accessing the website from IIS, it was straight-away redirecting user to a login page. (which obviously was throwing the error, as the windows application is not suppose to have login page).
I checked all configurations on IIS, and also could see only 'Windows Authentication" enabled, which was quite correct.
Though I haven't found any particular reason why it would be happening, however, I learned how to fix this :)
Add following keys in "<appSettings>" section of application's web.config file.

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

and restart the site on IIS. That should do the magic!
If the issue is too strange, the solution is more than strange...

Hope this saves someone's time and effort :)