Thursday, 10 March 2011

IIS7 & IIS Express 401 Access is denied due to invalid credentials Issue

I have been working on a large web application using MVC3, NHibernate using IIS Express to debug and IIS7 to stage. I'm using the membership services provided by ASP.NET to handle user authentication and provide security to the system. However I kept running across an issue, when accessing remotely, that was preventing me from logging in. Whenever I tried to view a page as a non logged in user I was returned a 404 Unauthorized error.



After searching around for a solution to why this was not displaying the correct page, even if it was redirecting to the login page I decided to try to set the error displaying to return more information. After adding <httpErrors errorMode="Details" /> to try and get a detail output from IIS the page started to work as expected.




With this option enabled the login page was now correctly displayed. This can be set without having to edit the web.config on IIS7 by editing the "Error Pages" features settings for your site in IIS. Set the Error Response to "Detailed errors"