61

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?

6 Answers 6

116

Add to your web.config:-

<system.web>
    <sessionState cookieName="foo" />
</system.web>
2
  • Any way of doing this without changing the web.config?
    – theB3RV
    Nov 10, 2016 at 13:12
  • Super Working Fine :)
    – Thulasiram
    Mar 2, 2021 at 4:57
15

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

<system.web>
    <sessionState cookieName="myCookieName" />
</system.web>
1
  • Just spotted as well...fixed...appreciated.
    – Kev
    Jun 19, 2009 at 9:53
8

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

4

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

<sessionState cookieName="foo" />
3

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.

1
  • 1
    downvoted because <sessionState> is not included by default in web.config in most cases, not really helpful.
    – MoSs
    Apr 5, 2014 at 23:06
0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.