Asp.Net身份和cookie名称 [英] Asp.Net Identity and cookie names
问题描述
我们有正在使用Asp.Net身份安全两个2应用程序。
We have 2 applications that are both using Asp.Net Identity for security.
他们什么都没有做与对方,但我正好是在这两个项目的开发商。
They have nothing to do with each other but I happen to be a developer on both projects.
我现在面临的Cookie名称很烦人的问题。如果我去APP1并登录然后APP2并登录,我从APP1断开连接。
I'm facing a quite annoying issue with the Cookie name. If I go to app1 and log in then to app2 and log in, I get disconnected from app1.
我的胡乱猜测是,这是因为2应用程序都共享同一个cookie名称。
My wild guess is that it is because the 2 applications are sharing the same cookie name.
所以,为了便于开发,也因为我觉得这是更好的我正在寻找一种方法来更改cookie的名称。
So for the ease of development and also because I think it is nicer I'm looking for a way to change the name of the cookie.
任何线索?
推荐答案
好找到了!
在默认情况下VS和身份将创建一个名为App_Start一个Startup.Auth.cs文件
By default VS and Identity will create a file in App_Start named Startup.Auth.cs
此文件包含下列code
This file contains the following code
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/Login"),
Provider = new CookieAuthenticationProvider
{
OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
validateInterval: TimeSpan.FromMinutes(30),
regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
}
});
要解决我们的问题,我们要设置的CookieName属性 CookieAuthenticationOptions
To fix our problem, we have to set the CookieName property of the CookieAuthenticationOptions
CookieName = "my-very-own-cookie-name"
就这样,仅此而已!
That's it, nothing more!
干杯
这篇关于Asp.Net身份和cookie名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!