是否可以在asp.net中将会话ID设置为我选择的值 [英] Is it possible to set session id to a value of my choice in asp.net

查看:65
本文介绍了是否可以在asp.net中将会话ID设置为我选择的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在使用ASP.Net Framework 4.5创建一个网站.

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

我知道使用SessionManager为当前httpContext生成新的sessionId的方法.我也相信sessionId字段是只读的,无法修改.但是,是否可以创建一个具有我选择的sessionId的新会话?

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?

例如,如果我希望当前会话ID的值为"ASDFGHIJKLQWERTY",是否可以创建一个?

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.

推荐答案

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

这篇关于是否可以在asp.net中将会话ID设置为我选择的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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