Rename ASP.NET_SessionId

asp.net

asp.net Problem Overview


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?

asp.net Solutions


Solution 1 - asp.net

Add to your web.config:-

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

Solution 2 - asp.net

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

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

Solution 3 - asp.net

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

Solution 4 - asp.net

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

<sessionState cookieName="foo" />

Solution 5 - asp.net

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.

Solution 6 - asp.net

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"
                };
            })

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionRobertView Question on Stackoverflow
Solution 1 - asp.netAnthonyWJonesView Answer on Stackoverflow
Solution 2 - asp.netKevView Answer on Stackoverflow
Solution 3 - asp.netRichardODView Answer on Stackoverflow
Solution 4 - asp.netRune GrimstadView Answer on Stackoverflow
Solution 5 - asp.netPaulo SantosView Answer on Stackoverflow
Solution 6 - asp.netmikusView Answer on Stackoverflow