How static variables are shared in a web session

I have a mvc webapi service setup that pulls and pops data from a sql server database.

As part of a web project containing webapi, I have a Static class that simply contains some global variables that are accessed from webapi methods. The following is a very simple example of a static class:

public static class SystemProperties
{
    public static int currentContactID;
}

When accessing WebApi, I share the ContactID with the Http call headers and set SystemProperties.CurrentContactID for it.

Than in webapi methods I get access to SystemProperties.CurrentContactID for data calls.

I found a problem when there are concurrent webapi calls that flow in CactactID.

My question is: how do members of a static class share between call sessions? It will be pretty much the last time in the best dressed and if the previous person is still there, and not the one whom he will turn over a new person who will rewrite the variables with his details?

Should I use a different method to store this data?

Thank you in advance

+4
source share
2 answers

You can use the current HttpContext to store items that will be used throughout the life of the HttpRequest

HttpContext.Current.Items["currentContactID"] = value

, , - http . HTTP- Items,

, cookie .

+2

, .

-API HttpRequestMessage. HTTP- ( DelegatingHandler) CurrentContactID HTTP-. CurrentContactID HttpRequestMessage.

HTTP-: http://www.asp.net/web-api/overview/working-with-http/http-message-handlers

HttpRequestMessage: http://msdn.microsoft.com/en-us/library/system.net.http.httprequestmessage.properties.aspx

, Properties HttpRequestMessage , .

0

All Articles