23

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

Kjartan
  • 17,961
  • 15
  • 70
  • 90
GajendraSinghParihar
  • 8,829
  • 11
  • 33
  • 63

1 Answers1

38

correct way is:

HttpContext.Current.Session.SessionID
Davecz
  • 1,178
  • 1
  • 18
  • 40