Rename ASP.NET_SessionId

I need to rename the ASP.NET_SessionId cookie created by default by ASP.NET. Let’s say I want it’s named “foo”. Is it possible?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Add to your web.config:-

<system.web>
    <sessionState cookieName="foo" />
</system.web>

Method 2

You can set this in the <sessionState> configuration setting in your web.config file:

<system.web>
    <sessionState cookieName="myCookieName" />
</system.web>

Method 3

See sessionState Element. look at the cookieName attribute, which will change it from the default of “ASP.NET_SessionId”.

Method 4

Yes. You can do it in your web.config file:

<sessionState cookieName="foo" />

Method 5

I don’t recall it correctly but I think you can rename it by changing the web.config file.

Seach for the sessionState element of the web.config.

Method 6

If anyone has got here looking for a solution compatible with ASP.NET Core, this can be normally specified within the Startup, as a parameter of the CookieBuilder, e.g:

 .AddCookie(options =>
            {
                options.LoginPath = new PathString("/Login");
                options.Cookie = new CookieBuilder()
                {
                    IsEssential = true,
                    SameSite = SameSiteMode.Lax,
                    SecurePolicy = CookieSecurePolicy.SameAsRequest,
                    Name = "MyOwnCookieName"
                };
            })


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x