I store user settings in HttpContext.Item ["user_settings"]. The user has two windows open with the same SessionId. In one, he changes the settings, but in the other, when the controller that updates the page is called, the value in user_settings does not change.

What's wrong?

  • Under the tags to the question there is an inscription to править . To illustrate the problem, you need to add the controller code that causes this problem. - Bulson

2 answers 2

HttpContext stores data only as part of processing a single HTTP request.

To store user settings, you should use either a session (Session, HttpSessionState) - in this case, the settings will be reset when the browser is closed or after a time, or the profile (Profile, ProfileInfo) - in this case, the settings will always be saved for the user. You can also store them in the database yourself.

  • Clear. Well, storing in the database is obvious. It is stored there. Just in order for the session to not want to constantly climb into the database. Once read at the start - and enough. - Deimon

HttpContext (with what you put in its Items ) exists during the processing of a single request. On another request, another context is created with a new (initially empty) Items set. Use Session .