作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我希望能够获得 session ID 当前经过身份验证的 session 的 网络方法 函数 where EnableSession = false .
我无法设置 EnableSession=true 在这个请求上,因为另一个页面上的另一个(长时间运行的)请求保留了 session 状态 锁定(EnableSessionState ==“True”而不是“Readonly”)。
是否有一致的方式获得 session ID 来自 ASP.NET session cookie 还是无 cookie session 的 URL?我可以自己编写代码,但我宁愿使用已经记录和测试过的函数。
非常感谢,
弗洛林。
最佳答案
似乎没有 ASP.NET 函数可以做到这一点,所以我自己编写了一个 hack,它现在有效......现在;):
private string GetSessionID(HttpContext context)
{
var cookieless = context.Request.Params["HTTP_ASPFILTERSESSIONID"];
if (!string.IsNullOrEmpty(cookieless))
{
int start = cookieless.LastIndexOf("(");
int finish = cookieless.IndexOf(")");
if (start != -1 && finish != -1)
return cookieless.Substring(start + 1, finish - start - 1);
}
var cookie = context.Request.Cookies["ASP.NET_SessionId"];
if (cookie != null)
return cookie.Value;
return null;
}
关于asp.net - 如何在 EnableSessionState ="False"的请求上获取 SessionID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1378352/
我是一名优秀的程序员,十分优秀!