且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

是否可以在asp.net中将会话ID设置为我选择的值

更新时间:2021-09-17 00:05:22

是的, SessionIDManager 类可以做到这一点,就像这样:

Yes, the SessionIDManager class can do that, like this:

SessionIDManager Manager = new SessionIDManager();

string NewID = Manager.CreateSessionID(Context);
string OldID = Context.Session.SessionID;
bool redirected = false;
bool IsAdded = false;
Manager.SaveSessionID(Context, NewID,out redirected, out IsAdded);
Response.Write("Old SessionId Is : " + OldID);
if (IsAdded)
{
    Response.Write("<br/> New Session ID Is : " + NewID);
}
else
{
    Response.Write("<br/> Session Id did not saved : ");
}