I have created HTTP handlers.
我已经创建了HTTP处理程序。
How do I create global variables for these handlers like I can with ASP.net web pages in global.asax?
如何使用global.asax中的ASP.net网页为这些处理程序创建全局变量?
2 个解决方案
#1
6
Add the variables to the Application instance:
将变量添加到Application实例:
System.Web.HttpContext.Current.Application["MyGlobalVariable"] = myValue;
Or, if the variable only need to live for the life of an individual request, use the Context object's Items collection:
或者,如果变量只需要在单个请求的生命周期中存活,请使用Context对象的Items集合:
System.Web.HttpContext.Current.Items["MyGlobalVariable"] = myValue;
Again, that will live for only the life of a single request.
同样,这将只适用于单个请求的生命。
#2
3
If your handler is specified as reusable you can also use static class members.
如果将处理程序指定为可重用,则还可以使用静态类成员。
#1
6
Add the variables to the Application instance:
将变量添加到Application实例:
System.Web.HttpContext.Current.Application["MyGlobalVariable"] = myValue;
Or, if the variable only need to live for the life of an individual request, use the Context object's Items collection:
或者,如果变量只需要在单个请求的生命周期中存活,请使用Context对象的Items集合:
System.Web.HttpContext.Current.Items["MyGlobalVariable"] = myValue;
Again, that will live for only the life of a single request.
同样,这将只适用于单个请求的生命。
#2
3
If your handler is specified as reusable you can also use static class members.
如果将处理程序指定为可重用,则还可以使用静态类成员。