C# – IIS 7.5 – Erro HTTP 401.0 – Unauthorized

asp.net-mvcchttp-status-code-401iisiis-7.5

I have a Application in Asp.net MVC running perfectly in Visual Studio 2015, with IIS EXPRESS (local computer).

I try execute this application in other computer (Windows Server 2008 R2 w/ IIS 7.5). I did a Deploy and i put in folder "C:\inetpub\wwwroot\testsite".

On execute localhost/testsite, the index page showying normaly, but, on submit the form (it's a login page), my IIS presents the "401.0 ERROR".

I am using "authentication mode forms":

<system.web>
    <compilation debug="true" targetFramework="4.5.2" />
    <httpRuntime targetFramework="4.5.2" />
    <authentication mode="Forms">
        <forms loginUrl="~/User/Login" timeout="2880" />
    </authentication>
</system.web>

Pool application is "DefaultAppPool". The Authentication: "Anonymous = ON", "Forms = ON", others options = OFF.

I tried various tips from other posts here from StackOverflow, But I could not solve my problem =(

Thanks!

Best Answer

Select the web application returning 401 - Unauthorized, and double-click the Authentication feature. Right-click the "Anonymous Authentication" provider and select edit. Switch the default anonymous user account ("IUSR") to ApplicationPoolIdentity. Now, right-click the web application in the left pane, select Edit Permissions..., select the Security tab, click Edit -> Add and add IIS APPPOOL\NameOfAppPool. Make sure the Application Pool Identity has read and execute permissions of the folder.

If you want to enable logging, check out this TechNet article: http://technet.microsoft.com/en-us/library/cc754631(WS.10).aspx

There is a setting for the anonymous user to use the credentials of the application pool identity or a specific user. Sometimes, it is defaulted to a specific user and not anonymous user If this is the issue in your case, following settings will hopefully fix it:

  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