angular - ASP.NET CORE 身份验证 cookie 消失
问题描述
英语不是第一语言,所以如果听起来很奇怪,请告诉我:)
我的开发环境
Asp.net Core 2.2 && Angular 10.0
目前,我有这个问题 3 个月了,但仍然无法弄清楚什么是解决方案。所以这次发生了问题
> Mysite.com ----> **Survey.com ----> Mysite.com**
当用户从“Survey.com”返回“Mysite.com”时,随机身份验证 cookie 会消失。下面是“Start.cs”的一部分。如果每个用户都丢失了他们的身份验证cookie,那么我可以清楚地看到导致问题的原因,但即使是同一台PC,它也是随机发生的(但如果我能够重新登录,它不会在一段时间内发生并突然发生)。
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
//Add indentity types
services.AddIdentity<TUserName, TTesterRole>(config =>
{
config.SignIn.RequireConfirmedEmail = true;
config.Password.RequireDigit = true;
config.Password.RequiredLength = 8;
config.Password.RequireNonAlphanumeric = true;
config.Password.RequireUppercase = true;
config.Password.RequireLowercase = true;
config.Password.RequiredUniqueChars = 1;
config.User.AllowedUserNameCharacters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-.,/;'`!@#$%^&*()_+[]{}";
})
.AddDefaultTokenProviders()
.AddTokenProvider<DataProtectorTokenProvider<TUserName>>("Default");
// Identity Services
services.AddTransient<IUserStore<TUserName>, PKRctUserDatastore>();
services.AddTransient<IRoleStore<TTesterRole>, PKRctRoleDatastore>();
services.AddTransient<PKRctDataTable>();
// linq error logs
services.AddLogging(loggingBuilder => {
loggingBuilder.AddConsole()
.AddFilter(DbLoggerCategory.Database.Command.Name, LogLevel.Information);
loggingBuilder.AddDebug();
});
// protected token life
services.Configure<DataProtectionTokenProviderOptions>(options =>
{
options.TokenLifespan = TimeSpan.FromDays(3);
});
// Add application services
services.AddTransient<IEmailSender, MessageSender>();
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
services.AddSignalR();
// In production, the Angular files will be served from this directory
services.AddSpaStaticFiles(configuration =>
{
configuration.RootPath = "ClientApp/dist";
});
//// set cookies - Identity cookie setting
services.ConfigureApplicationCookie(options =>
{
options.Cookie.HttpOnly = true;
options.Cookie.SecurePolicy = CookieSecurePolicy.SameAsRequest;
options.Cookie.SameSite = SameSiteMode.Lax;
options.Cookie.Name = "MYIDENTITY";
options.Cookie.IsEssential = true;
options.LoginPath = "/Account/Login";
options.ExpireTimeSpan = TimeSpan.FromDays(3);
options.ReturnUrlParameter = CookieAuthenticationDefaults.ReturnUrlParameter;
options.SlidingExpiration = true;
});
请帮我!
解决方案
推荐阅读
- ios - 如何在 Swift 的 UITableViewCell 中加载字典数据?
- android - ArrayList readLines
- python - 正确描绘 matplotlib python 中的趋势,如电子表格图表
- r - 如何减少 R 中分段图中的空白空间?
- c++ - 如何修改 PCL 体素网格实现?
- javascript - 输入范围滑块的 Javascript 代码在 Internet Explorer 11 中不起作用
- android - 谷歌卫星地图的最佳替代品是什么?
- vba - PowerPoint - VB 宏将 OnClick 动画添加到形状
- r - 确定R中总体标准差的函数是什么?
- python - 为什么从另一个创建新对象的程序执行函数然后访问它会返回错误