How to get SessionID by request, where EnableSessionState = "False"

I want to get the SessionID of the current authenticated session in the WebMethod function , where EnableSession = false .

I cannot set EnableSession = true in this request because another (long) request on another page blocks SessionState (EnableSessionState == "True" not "Readonly").

Is there a consistent way to get the SessionID from an ASP.NET or Url session cookie for cookieless sessions? I can encode it myself, but I would prefer to use a function that is already documented and tested.

Thank you very much,
Florin.

+3
source share
2 answers

There seems to be no ASP.NET function that can do this, so I made my own hack that works ... for now;):

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;
}
+4
source

HttpContext.Current.Session.SessionID

-1
source

Source: https://habr.com/ru/post/1716889/


All Articles