Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to programmatically get session cookie name?

Tags:

c#

asp.net

The default cookie name for the Session Id in ASP.NET is ASP.NET_SessionId. It's also possible to change this name to something else like <sessionState cookieName="FooBar" />.

Is there a member to easily access this name like with FormsAuthentication.FormsCookieName?

like image 792
TheCloudlessSky Avatar asked Sep 17 '10 22:09

TheCloudlessSky


People also ask

How to get Session cookie in c#?

Asp.net does it for you. So whenever you access Session dictionary your session will already be preserved if it existed from your previous request(s). If there is none (or expired) it will also be automatically created so adding items to it will make it work without a problem. var o = Session["SomeKey"];

What is ASP Net_SessionId?

Net_SessionId is a cookie which is used to identify the users session on the server.

Is session independent of cookies by default?

By default, SessionID values are stored in a cookie. However, you can also configure the application to store the SessionID value in the URL for a "cookieless" session. We are developing a web application that has three pages.


1 Answers

Taking into account that you say that you set an different name for the cookie on the web.config then I'd say you could read the cookie name from there

SessionStateSection sessionStateSection =   (System.Web.Configuration.SessionStateSection)   ConfigurationManager.GetSection("system.web/sessionState");  string cookieName =  sessionStateSection.CookieName; 
like image 114
Claudio Redi Avatar answered Oct 10 '22 17:10

Claudio Redi