24

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
  • 18,591
  • 15
  • 71
  • 96
GajendraSinghParihar
  • 9,051
  • 11
  • 36
  • 64

1 Answers1

39

correct way is:

HttpContext.Current.Session.SessionID
Davecz
  • 1,199
  • 3
  • 19
  • 43