zoukankan      html  css  js  c++  java
  • Generating a new ASP.NET session in the current HTTPContext

    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

  • 相关阅读:
    iOS必备知识点
    stringByReplacingOccurrencesOfString
    iPhone X 设计适配指南 & iOS 11 新特性
    block与property
    swift开发笔记04
    category重写系统方法的调用顺序是怎么样的?
    Error: Chunk.entry was removed. Use hasRuntime()错误解决
    李阳音标速成MP3文本
    JavaScript权威指南(第6版)(中文版)笔记
    Idea检入boss项目
  • 原文地址:https://www.cnblogs.com/dupeng0811/p/generating-a-new-asp-net-session-in-the-current-httpcontext.html
Copyright © 2011-2022 走看看