Thursday, August 11, 2016

ASP.NET: 401 unauthorized access is denied due to invalid credentials

Solution 1: (this will end up with @User.Identity.IsAuthenticated be empty string)
  • In IIS, select the website you're having the issue with.
  • In the IIS section, select 'Authentication'.
  • Right click on Anonymous Authentication and select 'Edit'
  • Check the 'Specified User' radio button and click on 'Set'
  • I entered my username, password and password confirmation and click ok.

ASP.NET: Identity not using Windows NT

Things to check
1) what is set in the web.config, windows authentication?
 mode="Windows" />

    users="?"/>
impersonate="false" />
2) Is anonymous access in IIS disabled? (enable Windows Authentication)
3) Try HttpConext.Current.User instead of Thread.CurrentPrincipal

ASP.NET: Login failed for user 'DOMAIN\MACHINENAME$'

Symptom: 












Root cause: web application is using the account which doesn't have access to connect to SQL server

Solution:

  1. add "NT AUTHORITY\NETWORK SERVICE" as SQL Server login, allow it to access the database (in the "User Mapping", assign the db_owner role for the corresponding databases)
  2. in IIS, create a custom application pool which is using "NetworkService" as Identity (make sure to use Integrated pipeline). then change the web application to use this pool