删除 cookie 名称中的 .AspNet 前缀

Remove .AspNet prefix in cookie name

使用OWIN Cookie认证中间件时,可以通过更改属性中的AuthenticationType来部分控制cookie的名称,f.e.:

app.UseCookieAuthentication(new CookieAuthenticationOptions
    {
        AuthenticationType = "Test",
        //...
    });

以上将产生一个名为 .AspNet.Test 的 cookie。有什么方法可以去掉 .AspNet. 前缀,因为我们相信它可以揭示我们正在使用的堆栈的有价值信息。

您需要设置 CookieName 属性。文档说:

Determines the cookie name used to persist the identity. The default value is ".AspNet.Cookies". This value should be changed if you change the name of the AuthenticationType, especially if your system uses the cookie authentication middleware multiple times.

app.UseCookieAuthentication(new CookieAuthenticationOptions
    {
        AuthenticationType = "Test",
        CookieName = "YourNameGoesHere",
        //...
    });