In one of my last projects, I was responsible for designing an enterprise wide ASP.Net application that would run on IIS and use integration windows authentication and connect to backend SQL Server database using integrated security i.e. SSPI. As you see, as per the requirement, everything (all network resource access) had to use integrated windows security mechanism i.e. “trusted connection”.
This is indeed a very common development scenario that we face on a regular basis when working with ASP.Net applications. In order to use Integrated Security, we simply check the ‘Integrated Windows NT Authentication’ (challenge/response) option in IIS, set ‘impersonate=true’ in our web.config file and we are ready to go.
Or are we?
A very common stumbling block that developers face with the above setup is when trying to connect to SQL Server, you end up getting one of the two following error message:
- Login failed for user '(null)'. Reason: Not associated with a trusted SQL Server connection.
- Microsoft OLE DB Provider for ODBC Drivers (0x80040E4D)
[Microsoft][ODBC SQL Server Driver][SQL Server]Login failed for user '\'.
- Microsoft OLE DB Provider for ODBC Drivers error '80040e4d'
[Microsoft][ODBC SQL Server Driver][SQL Server]Login failed for user 'NT AUTHORITY\ANONYMOUS LOGON'.
- SQL Server authentication
- Windows NT authentication
- Use ‘Basic Authentication’
- Use anonymous access and follow steps to setup proper authentication (refer the article http://support.microsoft.com/kb/247931/)
- Use Windows NT Authentication and use a specific “generic domain account” (ensure it has been given appropriate access and level of permission to the SQL database). Then use either of the following two ways to provide the generic user credential:
- Specify a username and a password in the connection string of the (this is similar to SQL Server authentication)
- Specify values in the impersonation settings and still use a trusted connection. You can also encrypt the web.config to protect the username/password information
Yes, absolutely. Here is the article on MSDN that explains it all. How To: Use Impersonation and Delegation in ASP.NET 2.0. It explains all the various Impersonation Scenarios namely:
- Impersonating the original caller. You want to access Windows resources that are protected with ACLs configured for your application's domain user accounts.
- Impersonating the original caller programmatically. You want to access resources predominantly by using the application's process identity, but specific methods need to use the original caller's identity.
- Impersonating a specific Windows identity. You need to use a specific identity or several Windows identities to access particular resources.
- Using delegation to access network resources by using an impersonated identity. You need to use an impersonated identity to access remote resources.


