Dynamically changing SessionID in C # ASP.NET

I'm curious if there is a way to dynamically change the session id from the SessionStateStoreProvider (or other custom module) context in C # for ASP.NET.

I am implementing a custom SessionStateStoreProvider, and I was thinking of increasing the session identifier to tell the store provider where to go, search for the session. I have implemented a custom SessionIDManager that allows me to increment the newly created session identifiers with the required tag. The problem is that the desired value of this tag can change throughout the session. For example, a session may be read from one location, but may need to be written to another location. In this case, the identifier would be initially tagged for location A, but when writing, the store would like to write to location B. The tag must be updated to display location B for the next reading session.

So, from the context of overriding SessionStateProviderBase ...

public override void SetAndReleaseItemExclusive(HttpContext context, 
    string id, SessionStateStoreData item, object lockId, bool newItem)

... is it possible to change the session identifier? I know that the HttpContext.Session.SessionID property is not configurable. Is there any other way of feedback with this update? Or is there a more appropriate transfer of this state through calls?

I am new to C # and web development in general, so any suggestions would be appreciated.

+3
source share
1 answer

After I asked this question, I made sure that it is not possible to dynamically change the session ID.

Instead of tagging the session ID with location information, I ended up setting the cookie using the HttpContext passed to the SessionStateStoreProvider interfaces:

context.Response.SetCookie(new HttpCookie(...));
+1
source

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


All Articles