Is it possible to set session id to a value of my choice in asp.net

℡╲_俬逩灬. 提交于 2019-12-08 00:29:32

问题


We are creating a web site with ASP.Net Framework 4.5.

I know the way to generate a new sessionId using SessionManager for the current httpContext. I also believe that the sessionId field is readonly and cannot be modified. However, is it possible to create a new session having a sessionId of my choice?

For example, if I want the current session Id to have a value "ASDFGHIJKLQWERTY", is it possible to create one?

The client insists that it can be done. However, I strongly believe that this is not possible. I'm unable to find any reference justifying that it can or cannot be done.

If there are any code or references that you can help me with, I would be very thankful.


回答1:


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 : ");
}


来源:https://stackoverflow.com/questions/17839283/is-it-possible-to-set-session-id-to-a-value-of-my-choice-in-asp-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!