1
votes

I'm using IIS 6 in Server 2003 and SQL server 2008 which sits ona seperate box. Now i would like to connect using the Application pool identity of the website to SQL server. But somehow whenever i display the identity in page_load method it always displays the windows account using which site was browsed. I have given the details below

Server : Windows Server 2003 Database : SQL server 2008 . Web server and DB sit on different machines. WebSite : Uses a custom app pool that runs using a custom domain account. Website has anonymous disabled and windows authentication enabled. Impersonation is not enabled in web.config.

I'm displaying the credentials using the below code :

Response.Write(HttpContext.Current.User.Identity.Name.ToString());
        WindowsIdentity id = WindowsIdentity.GetCurrent();
        Response.Write(id.Name);

Now i need a way of using the identity of app pool to connect to database. Please let me know how to do this. If i set the website anonymous account as the app pool identity everything works fine but i dont want to do that. Now authentication just flows as anonymous to the SQL server and it throws exception.

2

2 Answers

0
votes

I'm not sure about IIS6, but in IIS8... In the advanced settings for the application pool in questions, there is an identity section. Set this to the windows credentials you want to use. Also set 'Load application profile' to true.

Then in your application, you just need to setup your connections string to use a trusted_connection instead of an SQL server username and password.

Just remember to set the windows account to have a password which never expires, unless you'll remember to update the app-pool when it does change (or the pool will stop.)

Dave

0
votes

This sounds like you have Windows Authentication enabled and are using IE to connect to the site? In this case the Windows Identity is passed through to IIS.