How to get Session Id In C#

Champ picture Champ · Sep 11, 2012 · Viewed 75.6k times · Source

what is the correct way to get session id in C#

String sessionId ;
sessionId = Session.SessionID;

or

 string sessionId = Request["http_cookie"];
 sessionId = sessionId.Substring(sessionId.Length - 24);

Actually i am totally new to C# and just jumped in a project where i find the second code and by Google i found the first code so anyone please tell me what is the actual code to be used

Answer

Davecz picture Davecz · Sep 11, 2012

correct way is:

HttpContext.Current.Session.SessionID