开发者

Changing SessionID Dynamically in C# ASP.NET

开发者 https://www.devze.com 2022-12-18 07:38 出处:网络
I\'m curious if there is a way to dynamically change the session ID from the context of a SessionStateStoreProvider (or some other customizable module) in C# for ASP.NET.

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

I am implementing a custom SessionStateStoreProvider, and I was thinking about augmenting the session ID to tell the 开发者_C百科store provider where to go look for a session. I've implemented a custom SessionIDManager, which lets me augment newly created session IDs with the required tag. The problem is that the desired value of that tag might change during the life of a session. For example, the session may be read from one location, but may need to written to a different location. In this instance the ID would have originally been tagged for location A, but on writing the store would want to write to location B. The tag should be updated to reflect location B for the next session read.

So, from the context of SessionStateProviderBase override...

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

... is it possible to change the session ID? I know that the HttpContext.Session.SessionID property is not settable. Is there some other way to feedback an update like this? Or is there a more appropriate to carry state like this across calls?

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


After asking this question, I became reasonably certain that it is not possible to change the Session ID dynamically.

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

context.Response.SetCookie(new HttpCookie(...));
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号