views:

389

answers:

2

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?

+4  A: 

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.

Jason Bunting
+3  A: 

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

Jason Whitehorn
thanks, this is a good alternative solution that I will investigate
hmak