HttpModule and static class, do multiple requests execute the same static data?

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

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

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

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

The loaded configuration data may differ for each request (based on the values ​​in the URL), so I do not want other requests to share static data after calling SetConfigName.

So the question is, do multiple queries use the same static data, or does each new request receive a separate copy of the static class? (And if the data is separated, how to avoid it? The only alternative to make it a non-stationary class?)

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

+3
source share
2 answers

Multiple queries use the same static data. The only way around this is to always return information based on the current query, and not just return the stored static data. If this is not an option, then yes, you need to make it a non-static class.

+1
source

. 1 , HttpContext.Current.Items.

+3

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


All Articles