博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Generating a new ASP.NET session in the current HTTPContext
阅读量:7282 次
发布时间:2019-06-30

本文共 1534 字,大约阅读时间需要 5 分钟。

void regenerateId(){    System.Web.SessionState.SessionIDManager manager = new System.Web.SessionState.SessionIDManager();    string oldId = manager.GetSessionID(Context);    string newId = manager.CreateSessionID(Context);    bool isAdd = false, isRedir = false;    manager.SaveSessionID(Context, newId, out isRedir, out isAdd);    HttpApplication ctx = (HttpApplication)HttpContext.Current.ApplicationInstance;    HttpModuleCollection mods = ctx.Modules;    System.Web.SessionState.SessionStateModule ssm = (SessionStateModule)mods.Get("Session");    System.Reflection.FieldInfo[] fields = ssm.GetType().GetFields(BindingFlags.NonPublic | BindingFlags.Instance);    SessionStateStoreProviderBase store = null;    System.Reflection.FieldInfo rqIdField = null, rqLockIdField = null, rqStateNotFoundField = null;    foreach (System.Reflection.FieldInfo field in fields)    {        if (field.Name.Equals("_store")) store = (SessionStateStoreProviderBase)field.GetValue(ssm);        if (field.Name.Equals("_rqId")) rqIdField = field;        if (field.Name.Equals("_rqLockId")) rqLockIdField = field;        if (field.Name.Equals("_rqSessionStateNotFound")) rqStateNotFoundField = field;    }    object lockId = rqLockIdField.GetValue(ssm);    if ((lockId != null) && (oldId !=null)) store.ReleaseItemExclusive(Context, oldId, lockId);    rqStateNotFoundField.SetValue(ssm, true);    rqIdField.SetValue(ssm, newId);}

来源http://stackoverflow.com/questions/1368403/generating-a-new-asp-net-session-in-the-current-httpcontext/4420114#4420114

 

转载地址:http://wezjm.baihongyu.com/

你可能感兴趣的文章
软件图标显示不正常的问题
查看>>
Golang websocket
查看>>
关于编码:Unicode/UTF-8/UTF-16/UTF-32
查看>>
C++ OpenSSL 之三:生成CSR文件
查看>>
amaze ui响应式辅助
查看>>
C++getline使用
查看>>
Spinner使用二
查看>>
android 隐藏输入法键盘
查看>>
Android jni 中打印logcat日志
查看>>
SSL和keystore生成、导入等配置
查看>>
The Eagles Hotel California Lyrics
查看>>
软件工程——课程评价
查看>>
OpenStack Placement Project
查看>>
微信支付问题
查看>>
购买类目的概率预测
查看>>
Ajax Step By Step2
查看>>
codeforces 701 B. Cells Not Under Attack
查看>>
当同时安装Python2和Python3后,如何兼容并切换使用详解(比如pip使用)
查看>>
Creating a Custom Page Layout in SharePoint 2013
查看>>
mysql foreignkey
查看>>