gpt4 book ai didi

asp.net - 如何在 EnableSessionState ="False"的请求上获取 SessionID

转载 作者:行者123 更新时间:2023-12-01 01:36:54 27 4
gpt4 key购买 nike

我希望能够获得 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com