Does BeginRequest and EndRequest for an ASP.NET HttpApplication always occur on the exact same thread for a given HTTP request from a client?
The reason I ask is that I am seeing some very strange behavior where a ThreadStatic variable is not null inside of an Init method for an IHttpModule.
I set this ThreadStatic variable to a value on BeginRequest and null it on EndRequest.
However, my IHttpModule Init method should be called outside of the BeginRequest/EndRequest period, so the only way I can think of that this ThreadStatic variable would have a value when my Init method is called is if EndRequest occurs on a different thread than BeginRequest and thus the value is still not null later on when ASP .NET tries to use that same thread to create a new HttpApplication instance…
I am running IIS 7 in integrated mode.
No. There are options to perform asynchronous operations in the request leading to the end of the request being handled on a different thread. This is not the normal case.
See the Async attribute of
@Pagedirective: http://msdn.microsoft.com/en-us/library/ydy4x04a.aspxFor an introduction to using asynchronous pages, see this MSDN Magazine article: “Asynchronous Pages in ASP.NET 2.0“.