makstaks
makstaks

Reputation: 2111

ASP.NET HTTP handlers and global variables

I have created HTTP handlers.

How do I create global variables for these handlers like I can with ASP.net web pages in global.asax?

Upvotes: 3

Views: 2718

Answers (2)

Jason Whitehorn
Jason Whitehorn

Reputation: 13685

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

Upvotes: 3

Jason Bunting
Jason Bunting

Reputation: 58969

Add the variables to the Application instance:

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:

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

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

Upvotes: 6

Related Questions