tags:

views:

186

answers:

2

I have written an ASP.NET HttpModule and I have a static helper class that is used to load and store configuration data for the life of the request.

Since static constructors must be parameterless, I have a static SetConfigName method that I call at the start of the processing of the HttpRequest.

    public static void SetConfigName (string configName)
    {
        // load data specific to given configName
    }

There are also static Get() methods that are called later during processing of the HttpRequest.

The configuration data that is loaded can be different for each request (based on values in the URL), so I do not want other requests to share the static data once I have called SetConfigName.

So the question is, do multiple requests share the same static data, or does each new request get a separate copy of the static class? (And if data is shared, how to avoid it? Is the only alternative to make it a non-static class?)

(By the way, I do not use global.asax.)

+1  A: 

Static data is shared between requests. To store static data for 1 request, you should use HttpContext.Current.Items.

Tommy Carlier
A: 

Multiple requests do share the same static data. The only way to get around it is to always return information based on the current request, rather than just returning saved static data. If that's not an option, then yes, you need to make it a non-static class.

Max Schmeling