views:

36

answers:

1

I have an asp.net application that runs on a custom app pool which runs under a service level account. I have anonymous access turned off in web.config. The web server is part of a domain. The application access a sql server which runs on the same machine.

Currently, for all users, I impersonate the service level account to access the Database. When lots of users are accessing the site, this slows the site down as the lsass process starts using the cpu.

I am not allowed to create a sql server account, I have to work with what I have. I am also not allowed to add each individual user to the database and give them specific access.

My question is, how can I set my application and datbase reletionship up such that I dont have to do impersonation of the Service level account and thus avoid CPU thrashing when website usage is high.

A: 

You shouldn't have to impersonate the service account. The service account is the account that needs access to the database and I suppose it already has. Have you already tried running your application without impersonating the service account when you access the database? This should work.

To perform a simple test, check the identity returned by WindowsIdentity.GetCurrent() (inside Page_Load for example). This should return the application pool identity and this is the identity that will be used to access the database.

Of course, this only works if you do not have client impersonation configured in your Web.config file. But since this is not a general practice except for some corner cases I suppose you don't use this. Client impersonation is not necessary for determining who the current user is, you should only use it when you want to access third-party systems (databases, fileshares, queues, ...) using the identity of the currently logged-on user (which is not a very scalable approach).

Ronald Wildenberg
client impersonation is actually configured in the web.config file.impersonate=true, with no user name and password.This is done so I can figure out who the user is as I need to make sure they are allowed to access the website in the first place.
You don't need client impersonation for that. I suppose you have an intranet site and Windows authentication? Then checking who your current user is, is done by calling Thread.CurrentPrincipal or HttpContext.Current.User. I also added some more information to my answer.
Ronald Wildenberg
Taking impersonation out of web.config file solved the problem. Now I dont have to impersonate programmatically.