aspnetboilerplate共享cookie对services.AddDataProtection()无效

时间:2018-04-04 10:44:25

标签: aspnetboilerplate .net-core-2.0

我有以下情况:

Server A:abpWeb; 
Server B:abpWeb;

A和B基于MyCompanyName.AbpZero模板,abp。 Net core 3.1.1版; aspnetboilerplate

浏览器访问权限A:abpWebB:abpWeb。但登录后,cookie共享无效。

A:User.Identity?。浏览器访问后,IsAuthenticated等于true A:登录;

但是在浏览器上刷新B:/ index,B:User.Identity?.IsAuthenticated等于false;

A和B的浏览器域相同。

我使用ASP.NET核心标识创建了两个新的ASP.NET Core 2.0 MVC应用程序,使用AddDataProtection正常的共享cookie是可以的。

我提到:
https://docs.microsoft.com/en-us/aspnet/core/security/cookie-sharing?tabs=aspnetcore2x

我在网上搜索了很长时间。但没用。请帮助或尝试提供一些如何实现这一点的想法。 提前谢谢。

1 个答案:

答案 0 :(得分:0)

用于加密/解密cookie的密钥可能正试图写入无效的文件夹中。

默认情况下,AddDataProtection尝试将这些键写入: %LOCALAPPDATA%\ASP.NET\DataProtection-Keys

只要有用于创建密钥路径的环境变量,您就需要将以下配置文件设置设置为true。

也请在此处查看我的其他答案: IIS - AddDataProtection PersistKeysToFileSystem not creating

修复:在%WINDIR%\System32\inetsrv\config\applicationHost.config中设置setProfileEnvironment=true。我认为您也必须重新启动IIS。