ASP.NET HTTP Handlers and Global Variables

I created HTTP handlers.

How to create global variables for these handlers as I can, with ASP.net webpages in global.asax?

+3
source share
2 answers

Add variables to the application instance:

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

Or, if the variable should live only for the life of a single request, use the collection of objects of the context object:

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

Again, this will only live for the life of a single request.

+5
source

If your handler is listed as reusable, you can also use static class members.

+3
source

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


All Articles