Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get Session Id In C#

Tags:

c#

sessionid

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

like image 924
GajendraSinghParihar Avatar asked Sep 11 '12 10:09

GajendraSinghParihar


People also ask

How do I get my session ID?

Session IDs are typically found in the Request (NCSA) field, the URI-Query (W3C), or the Cookie field: If the ID is found in the URL itself, it will be in the Request field for Apache servers and in the URI Query field for IIS servers.

What is session ID in C#?

The SessionID property is used to uniquely identify a browser with session data on the server. The SessionID value is randomly generated by ASP.NET and stored in a non-expiring session cookie in the browser. The SessionID value is then sent in a cookie with each request to the ASP.NET application.

How can controller get the session ID?

The Controller consists of the following two Action methods. Inside this Action method, simply the View is returned. When the Get SessionId Button is clicked, SetSession Action method is executed which saves the value to the Session using the SetString method. Then the Session ID is retrieved from HttpContext.

What is session ID example?

The session ID can be defined by a command line option or a resource. The session ID can be a single value; for example “Smith". A set of session Ids can be defined; for example, Smith+n where n is 3 would make 3 session Ids available, “Smith1", “Smith2", and “Smith3". Each 5250 session has a unique session ID.


1 Answers

correct way is:

HttpContext.Current.Session.SessionID
like image 190
Davecz Avatar answered Oct 14 '22 16:10

Davecz