tk网站的dns修改,网站开发教程H5,网站logo用什么来做,汕头网站设计电话这是这两天ASP.NET Core迁移中遇到的一个问题。2个ASP.NET Core站点#xff08;对应于2个不同的ASP.NET Core Web应用程序#xff09;#xff0c;2个站点都可以登录#xff0c;但在其中任1个站点登录后#xff0c;在当前站点处于登录状态#xff0c;访问另外1个站点却处于… 这是这两天ASP.NET Core迁移中遇到的一个问题。2个ASP.NET Core站点对应于2个不同的ASP.NET Core Web应用程序2个站点都可以登录但在其中任1个站点登录后在当前站点处于登录状态访问另外1个站点却处于未登录状态。 开始以为是CookieAuthenticationOptions的设置不一致引起的检查代码后确认AuthenticationSchemeCookieNameCookieDomain都是一样的。 app.UseCookieAuthentication(new CookieAuthenticationOptions
{CookieName .AspNetCore.Cookies,CookieDomain .cnblogs.com}); AuthenticationScheme的默认值是Cookies 之后怀疑是DataProtection的密钥不一致引起的我们用的是同一个阿里云redis实例存储密钥存储方式上不会造成不一致。 if (Environment.IsDevelopment()) { services.AddDistributedMemoryCache(); } else { services.AddDistributedServiceStackRedisCache(options { Configuration.GetSection(redis).Bind(options); //Workaround for deadlock when resolving host name IPAddress ip; if (!IPAddress.TryParse(options.Host, out ip)) { options.Host Dns.GetHostAddressesAsync(options.Host) .Result.FirstOrDefault(a a.AddressFamily AddressFamily.InterNetwork).ToString(); } }); } services.AddDataProtection().PersistKeysToDistributedStore(); 为了进一步确认密钥是否是一样的修改了 DataProtection.DistributedStore 的源代码将密钥打印在控制台运行后确认2个站点用的密钥是一样的。 public IReadOnlyCollectionXElement GetAllElements() { var data _cache.GetString(_key); Console.WriteLine(data); if (!string.IsNullOrEmpty(data)) { return XDocument.Parse(data).Root.Elements().ToList().AsReadOnly(); } else { return new ListXElement().AsReadOnly(); } } 后来突然想到 services.AddDataProtection() 是不是有什么配置选项F12之后发现果然有个DataProtectionOptions public static IDataProtectionBuilder AddDataProtection(this IServiceCollection services, ActionDataProtectionOptions setupAction); 继续F12发现DataProtectionOptions只有1个属性ApplicationDiscriminator点开它的注释后问题的答案跃然而出 // // Summary: // Provides global options for the Data Protection system. public class DataProtectionOptions { public DataProtectionOptions(); // // Summary: // An identifier that uniquely discriminates this application from all other applications // on the machine. The discriminator value is implicitly included in all protected // payloads generated by the data protection system to isolate multiple logical // applications that all happen to be using the same key material. // // Remarks: // If two different applications need to share protected payloads, they should ensure // that this property is set to the same value across both applications. public string ApplicationDiscriminator { get; set; } } 原来不同的ASP.NET Core应用程序要使用同样的加解密方式除了共享密钥还要设置同样的ApplicationDiscriminator。 添加如下的代码后问题立马解决。 services.AddDataProtection(options options.ApplicationDiscriminator cnblogs.com); 原文地址http://www.cnblogs.com/dudu/p/6495951.html .NET社区新闻深度好文微信中搜索dotNET跨平台或扫描二维码关注