2009-09-04 25 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

相關問題