ASP.NET HTTP 处理程序和全局变量

标签 asp.net httphandler

我已经创建了 HTTP 处理程序。

如何像在 global.asax 中使用 ASP.net 网页一样为这些处理程序创建全局变量?

最佳答案

将变量添加到应用程序实例中:

System.Web.HttpContext.Current.Application["MyGlobalVariable"] = myValue;

或者,如果变量只需要在单个请求的生命周期内存在,请使用 Context 对象的 Items 集合:

System.Web.HttpContext.Current.Items["MyGlobalVariable"] = myValue;

同样,这只会在单个请求的生命周期内有效。

关于ASP.NET HTTP 处理程序和全局变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/210620/

相关文章:

asp.net - 使用冒号(:) in a url with ASP. NET/IIS

asp.net - Sharepoint 列表的开源替代方案

asp.net - 在 ASP 中使用其他项目的用户控件

asp.net - 如何理解 google chrome 中针对 Asp.net 提供的静态资源的安全警告

asp.net - 使用 ASP.NET GenericHandlers 时管理 ASP.NET 中的 session 超时

android - onSuccess(int, Header[], JSONObject) 未被覆盖,但收到回调

asp.net - 用于 ASP.NET 的 KCFinder

asp.net - 如何在不访问 .ASP 文件的情况下自定义 Volusion 模板

iis-7.5 - 403 禁止所有 *.axd 文件 - aragh

asp.net - 如何在 IIS7 中为 HttpHandler 注册多个路径?