Do ASP.NET Requests always BeginRequest and EndRequest on the same thread?(ASP.NET 请求总是 BeginRequest 和 EndRequest 在同一个线程上吗?)
问题描述
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.
Does BeginRequest and EndRequest for an ASP .NET HttpApplication always occur on the exact same thread for a given HTTP request from a client?
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 @Page
directive: http://msdn.microsoft.com/en-us/library/ydy4x04a.aspx
For an introduction to using asynchronous pages, see this MSDN Magazine article: "Asynchronous Pages in ASP.NET 2.0".
这篇关于ASP.NET 请求总是 BeginRequest 和 EndRequest 在同一个线程上吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:ASP.NET 请求总是 BeginRequest 和 EndRequest 在同一个线程上吗?


- 如何用自己压缩一个 IEnumerable 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- 输入按键事件处理程序 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01