ASP.NET身份和cookie名称
-
21-12-2019 - |
题
我们有2个应用程序,它都使用ASP.NET身份进行安全性。
他们彼此无关,但我碰巧是两个项目的开发人员。
我面临着与cookie名称相当讨厌的问题。如果我去App1并登录到App2并登录,我会与App1断开连接。
我的疯狂猜测是,它是因为2个应用程序共享相同的cookie名称。
因此,为了易于发展,而且我认为它是更好的,我正在寻找一种改变cookie名称的方法。
任何线索?
解决方案
好的,找到它。
默认情况下,VS和Identity将在App_start中创建一个名为startup.auth.cs的文件。
此文件包含以下代码
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))
}
});
.
要修复我们的问题,我们必须设置CookieAuthenticationOptions
的cookiename属性
CookieName = "my-very-own-cookie-name"
.
就是这样;没有。
欢呼!
其他提示
for formsauthentication,cookie name的更改是通过web.config:
<authentication mode="Forms" >
<forms loginUrl="~/Account/LogIn" timeout="2880" name=".cookie2" />
</authentication>
. 不隶属于 StackOverflow