401 Unauthorized: Access is denied due to invalid credentials

195,143

Solution 1

I realize this is an older post but I had the same error on IIS 8.5. Hopefully this can help another experiencing the same issue (I didn't see my issue outlined in other questions with a similar title).

Everything seemed set up correctly with the Application Pool Identity, but I continued to receive the error. After much digging, there is a setting for the anonymous user to use the credentials of the application pool identity or a specific user. For whatever reason, mine was defaulted to a specific user. Altering the setting to the App Pool Identity fixed the issue for me.

  1. IIS Manager → Sites → Website
  2. Double click "Authentication"
  3. Select Anonymous Authentication
  4. From the Actions panel, select Edit
  5. Select Application pool Identity and click ok

Hopefully this saves someone else some time!

Solution 2

If you're using IIS 7 do something like this:

  1. Select your site.
  2. Click on error pages.
  3. Edit feature settings.
  4. Select detailed errors.

Solution 3

Make sure that you enabled anonymous authentication on iis like this:

enter image description here

Solution 4

In case anyone is still looking for this, this solved the problem for us:

To whoever this may help, this saved my life...

IIS 7 was difficult for figuring out why i was getting the 401 - Unauthorized: Access is denied due to invalid credentials... until i did this...

  1. Open IIS and select the website that is causing the 401
  2. Open the "Authentication" property under the "IIS" header
  3. Click the "Windows Authentication" item and click "Providers"
  4. For me the issue was that Negotiate was above NTLM. I assume that there was some kind of handshake going on behind the scenes, but i was never really authenticated. I moved the NTLM to the top most spot, and BAM that fixed it.

Here is the link where this was found.

Solution 5

I realize its an old question, but this came up in my searches. Had a similar issue for an MVC application recently built, deployed for the first time, and Authentication mechanism wasn't completely hashed out.

It wasn't an IIS setting in my case, it was a Controller that was not [AllowAnonymous] decorated. I was using a Render.Action/Html.Action in a Layout.cshtml and the User was unauthenticated. So the Layout tried to load an Authenticated Action in an UnAuthenticated context.

Once I updated the action to AllowAnonymous, the problem went away, and this is what led me to it.

Hope this helps someone.

Share:
195,143
java.manish.2015
Author by

java.manish.2015

Graduated from University of Central Missouri (MS IT) Engineering specialist, have knowledge and experience in .net as well java fields equally. Having experience of complete software development life cycle.

Updated on January 13, 2022

Comments

  • java.manish.2015
    java.manish.2015 over 2 years

    I am using IIS Express to deploy MVC4 application. This website runs perfectly on same computer. But in Lan it gives me error 401.

    <authentication mode="Forms">
        <forms loginUrl="~/" slidingExpiration="true" timeout="20">
        </forms>
    </authentication>
    

    In home controller

    [HttpPost]
    [AllowAnonymous]        
    public ActionResult Index(LoginModel model, string returnUrl)
    {
    }
    

    I am starting IIS server from command prompt in Administrator mode. IIS responds to the request with error 401.

    Any clue?

  • Jamie
    Jamie over 2 years
    WOW! This just ended my week long headache. I just moved a web app from Windows auth to ADFS AND upgraded the server to 2019 and was about to give up and go back to the old 2012 server. Thank you!!!!!!!!