Showing posts with label ASP.NET Authentication. Show all posts
Showing posts with label ASP.NET Authentication. Show all posts

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 :)

Wednesday, April 11, 2012

Check Authentication Mode in ASP.NET

At times you may require to check if the current authentication mode (that is, if windows or forms)

You can set the authentication mode using following your web.config file under System.Web section.

authentication mode="Windows"

To know the authentication mode within your page, you can use -
"HttpContext.User.Identity.AuthenticationType".

For Forms Authentication, it will return "Forms".
For Windows, it will return "NTLM" (that stands for NT LAN Manager)