如何删除或更改ASP.NET MVC 5默认cookie

时间:2014-04-01 17:52:43

标签: asp.net asp.net-mvc cookies owin

我使用“个人用户帐户”(OWIN)创建了一个ASP.NET MVC 5应用程序。我正在关注this guide以删除不必要的HTTP标头,这些标头公开了我不想公开的内容。

所有内容都已正确删除,但还有一件事显示这是一个ASP.NET应用程序,它是默认的cookie:

Cookie:ASP.NET_SessionId=gpryojsaen2hnukmzoh5xbuv;

有没有办法将名称更改为其他名称?

2 个答案:

答案 0 :(得分:4)

我需要将其添加到web.config

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

答案 1 :(得分:3)

鉴于您正在使用OWIN,您应该可以更改app.UseCookieAuthentication来电中的设置。类似的东西:

public void ConfigureAuth(IAppBuilder app)
{
    app.UseCookieAuthentication(new CookieAuthenticationOptions
    {
        AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
        CookieName = "ChangeMe",
        /* other options */
    });
}