Timer Thread Identity

  • Thread starter Thread starter brian
  • Start date Start date
B

brian

I have an ASP.Net application that uses impersonation.
This works fine for accessing/executing the application.
However, the app utilizes a timer, that when fired uses
the <machine>ASPNET identity.

In order to correct this problem I've modified the
Machine.config file in the
\Microsoft.Net\Framework\v1.1.4322 folder. However, this
didn't solve the problem; instead of using the user id and
password specified in Machine.Config, the thread executed
with <machine>ASPNET identity.

I sure would appreciate it if someone could shine some
light on this issue for me.

Thanks.

brian
 
Timer delegates are run on threadpool threads, these are running in the security context of the process (asp.net) not the context of
the calling thread.
There is nothing you can do about this.
Question you should ask yourself:
- why do you use timers in asp.net applications in the first place, and second why do you execute code in a timer event handler
which requires a certain security context?

Willy.
 
Willy. The reason I am using a timer is that I have users
adding records to a folder. It is important that the
contents of this folder be written to SQL Server on a
regular interval, hence the timer. However, you do make at
least one valid point; why use a timer? Granted this tool
is available for me to use, but I could just as easily use
a counter, and write the contents of the folder to SQL
Server everytime the document count reaches 100.

brian

-----Original Message-----
Timer delegates are run on threadpool threads, these are
running in the security context of the process (asp.net)
not the context of
the calling thread.
There is nothing you can do about this.
Question you should ask yourself:
- why do you use timers in asp.net applications in the
first place, and second why do you execute code in a timer
event handler
 
Brian,
The purpose of my question was, how do you synchronize both, the service time (time to handle the asp request) and the timer
interval?
If the former is shorter than the latter, your page object could be GC'd before the timer expires, unless you take some precautions,
you will lose the timer event.
A possible solution to your problem windows identity doesn't flow when using threadpool threads (and delegates)' is to move (part
of) your DB updates to a COM+ server-type component (ServicedComponent) running with a fixed identity.
Each time the timer fires you simply call (synchronously) a method on the component, you could even make the call asynchronous by
using MSMQ.

Willy.
 
Back
Top