RE: ? - Database Query & Saving to Application Cache
From: Jonathan Ruckert (jruckert_AT_novaworks_DOT_com_DOT_au)
Date: Thu, 25 Mar 2004 21:01:05 -0800
The Application_Start event is fired by the worker process that runs under the MACHINENAME\ASPNET user account, and so this is not the best place to put the db code. Again the Session_Start event with impersonation is linked to the current thread and their identity, so will fire every time a new session is started etc.
If you wish to compromise this my suggestion - create a SQL Server User account on the DB and then login using this during the Application_Start event.
----- Raja wrote: -----
I have an ASP.NET application that uses Windows authentication and impersonation. In my Global.asax file--the Application_Start event--I have code to access and query my database to store a dataset into Application Cache. However, I get a DB permissions error.
The call to the database in the Global.asax file is using MACHINENAME\ASPNET (which doesn't have access to my database), not the authenticated user DOMAINNAME\USERNAME (which does have database access). So, it seems as though ASP.NET impersonation doesn't happen until after the Application_Start event has fired in Global.asax. Does this sound correct? Or, am I missing something else?
Anyway, to the real question: Using Windows auth. with impersonation, where is the best place to query a database to store a dataset into Application Cache? And, how? Right now it works in Session_Start, but then every user that accesses the app. also queries the database.
Thanks for you help