2009-09-04 23 views
3

我希望能够得到当前验证会话的的SessionID的WebMethod函数,其中EnableSession =假的请求得到的SessionID。如何在其中的EnableSessionState =“假”

我无法设置EnableSession这个请求=真,因为不同的页面上的其他(长期运行)请求保持SessionState的锁定(==的EnableSessionState“真”而不是“只读”)。

有没有得到的SessionID无论从ASP.NET会话cookie或Cookie会话的网址的一致呢?我可以编写自己,但我宁愿使用已文档和测试功能。

非常感谢你,
弗罗林。

回答

4

似乎没有ASP.NET功能,能做到这一点,所以我做了我自己的,它的工作原理...现在的黑客攻击):

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; 
} 
-1

HttpContext.Current.Session.SessionID

+0

会议不适用于这个要求,所以HttpContext.Current.Session == NULL。 – 2009-09-04 18:19:42

相关问题