Does ASP.NET always require BeginRequest and EndRequest in the same thread?

Does BeginRequest and EndRequest for ASP.NET HttpApplication always occur in the same thread for a given HTTP request from a client?

I ask that I see very strange behavior when the ThreadStatic variable is not null inside the Init method for IHttpModule.

I set this ThreadStatic variable to BeginRequest and null to EndRequest.

However, my IHttpModule Init method should be called outside of the BeginRequest / EndRequest period, so the only way I can think that this ThreadStatic variable will matter when the Init method is called is if EndRequest occurs in a different thread than BeginRequest, and so thus, the value is still not null later when ASP.NET tries to use the same thread to create a new HttpApplication instance ...

I am running IIS 7 in integrated mode.

+3
source share
3 answers

Are BeginRequest and EndRequest for ASP.NET HttpApplication running in the same thread for this HTTP request from the client?

. , . .

. Async @Page: http://msdn.microsoft.com/en-us/library/ydy4x04a.aspx

. MSDN Magazine: " ASP.NET 2.0".

+3

, , ... , .

ThreadStatic STATIC. , ...

+1

, .

, "" HTTP- HttpContext.Current.Items. [ThreadStatic] - ASP.NET , . , ThreadStatic ASP.NET.

, EndRequest HttpContext.

, -, [ThreadStatic] HttpContext http://piers7.blogspot.co.nz/2005/11/threadstatic-callcontext-and_02.html

:
http://www.hanselman.com/blog/ATaleOfTwoTechniquesTheThreadStaticAttributeAndSystemWebHttpContextCurrentItems.aspx

And Jon Skeet has a good SO answer here:
CallContext vs ThreadStatic

0
source

Source: https://habr.com/ru/post/1763352/


All Articles