会话ID在登录前和登录后保持不变 [英] Session ID remains the same before login and after login

查看:91
本文介绍了会话ID在登录前和登录后保持不变的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

登录前和登录后会话ID保持不变

如何修复它。



当我使用登录页面登录然后我想要更改会话ID。

表示当我打开登录页面然后我登录后有一个ASP.NET_SessionId,这个ASP.NET_SessionId保持不变。

所以我想在登录后更改这个ASP.NET_SessionId并保持任务将继续使用新的ASP.NET_SessionId。所以你能告诉我该怎么做。



如果你回答这个问题,我非常感谢你。

Session ID remains the same before login and after login
How to fix it.

when i login with login page then i want to change the session id.
means when i open login page then i have a one ASP.NET_SessionId after login this ASP.NET_SessionId remain same.
so i want to change this ASP.NET_SessionId after login and remain task will going on with new ASP.NET_SessionId . so can you tell me how to do.

I am very thankful to you if you reply for that.

推荐答案

请在登录帐户时更改会话ID,例如



Please change session id while you are loggin into the account like

Session["userid"] = userId





when你是登出使用方法





when you are loggin out use method

Session.abandon()


只需调用此函数,无论何时需要更改ASP.NET_Session ID



Just Invoke this Function, Wherever you need to change the ASP.NET_Session ID

Sub RegenerateID()
        Dim manager
        Dim oldId As String
        Dim newId As String
        Dim isRedir As Boolean
        Dim isAdd As Boolean
        Dim ctx As HttpApplication
        Dim mods As HttpModuleCollection
        Dim ssm As System.Web.SessionState.SessionStateModule
        Dim fields() As System.Reflection.FieldInfo
        Dim rqIdField As System.Reflection.FieldInfo
        Dim rqLockIdField As System.Reflection.FieldInfo
        Dim rqStateNotFoundField As System.Reflection.FieldInfo

        Dim _nbrqPath As System.Reflection.FieldInfo


        Dim store As SessionStateStoreProviderBase
        Dim field As System.Reflection.FieldInfo
        Dim lockId
        manager = New System.Web.SessionState.SessionIDManager
        oldId = manager.GetSessionID(Context)
        newId = manager.CreateSessionID(Context)
        manager.SaveSessionID(Context, newId, isRedir, isAdd)
        ctx = HttpContext.Current.ApplicationInstance
        mods = ctx.Modules
        ssm = CType(mods.Get("Session"), System.Web.SessionState.SessionStateModule)
        fields = ssm.GetType.GetFields(System.Reflection.BindingFlags.NonPublic Or System.Reflection.BindingFlags.Instance)
        store = Nothing : rqLockIdField = Nothing : rqIdField = Nothing : rqStateNotFoundField = Nothing : _nbrqPath = Nothing
        For Each field In fields
            If (field.Name.Equals("_store")) Then store = CType(field.GetValue(ssm), SessionStateStoreProviderBase)
            If (field.Name.Equals("_rqId")) Then rqIdField = field
            If (field.Name.Equals("_rqLockId")) Then rqLockIdField = field
            If (field.Name.Equals("_rqSessionStateNotFound")) Then rqStateNotFoundField = field

        Next
        lockId = rqLockIdField.GetValue(ssm)
        If ((Not IsNothing(lockId)) And (Not IsNothing(oldId))) Then store.ReleaseItemExclusive(Context, oldId, lockId)
        rqStateNotFoundField.SetValue(ssm, True)
        rqIdField.SetValue(ssm, newId)
    End Sub


这篇关于会话ID在登录前和登录后保持不变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆