Flo*_*bau 4 asp.net session-state sessionid webmethod
我希望能够在WebMethod函数中获取当前经过身份验证的会话的SessionID,其中EnableSession = false.
我无法在此请求上设置EnableSession = true,因为另一个页面上的另一个(长时间运行的)请求会使SessionState保持锁定状态(EnableSessionState =="True"而不是"Readonly").
是否有一致的方法从ASP.NET会话cookie或Url获取SessionID用于无cookie会话?我可以自己编写代码,但我宁愿使用已经记录和测试过的函数.
非常感谢,
弗罗林.
似乎没有可以做到这一点的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;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7945 次 |
| 最近记录: |