用户配置文件和 HKLM 注册表均不可用。应用程序退出时,受保护的数据将不可用

Neither user profile nor HKLM registry available. Protected data will be unavailable when application exits

我是 运行 一个 B2B 网站,客户可以在这里登录、查看目录和下订单。网站运行于 一个子域(我认为这是一个重要的旁注,因为 this)。当客户完成订单并点击下订单按钮时​​,他们将被送回登录屏幕,订单丢失。有时,这段时间会更短,有时会更长。与正在重新启动的应用程序池有关吗?

所以我创建了一个日志记录功能来查看发生了什么,并发现每当用户登录时,都会创建以下日志:

Using an in-memory repository. Keys will not be persisted to storage.

Neither user profile nor HKLM registry available. Using an ephemeral key repository. Protected data will be unavailable when application exits.

No XML encryptor configured. Key {6a86c315-5115-4d16-a3f8-2ec49450b794} may be persisted to storage in unencrypted form.

我搜索了这些并发现 webpage explaining in detail why this happens. The prblem being a bug in IIS (which it is unlikely to be corrected) 解决方案是更改 IIS 上的设置,但我无法做到。我在共享主机上。我已经与他们的支持人员讨论过这个问题,他们说他们不能更改 IIS 上共享服务器的设置。因此,在 IIS 上将 Load User Profile 设置为 True 对我来说不是一个选项。

我还在某处读到,使用 Azure 应用程序我可以更改生成的密钥的存储位置。不过我还没有调查过这个。

那么有什么解决这个问题的想法吗?专用服务器还是使用 Azure 服务是我唯一的选择?

作为参考,下面是我的 Startup.cs 文件中的相关部分

    services.Configure<IdentityOptions>(options =>
    {
        // password settings
        options.Password.RequireDigit = false;
        options.Password.RequireLowercase = false;
        options.Password.RequireUppercase = false;
        options.Password.RequireNonAlphanumeric = false;
        options.Password.RequiredLength = 6;
        options.Password.RequiredUniqueChars = 1;

        // lockout settings
        options.Lockout.DefaultLockoutTimeSpan = System.TimeSpan.FromMinutes(5);
        options.Lockout.MaxFailedAccessAttempts = 5;
        options.Lockout.AllowedForNewUsers = true;

        // sign in settings
        options.SignIn.RequireConfirmedEmail = true;
        // user settings
        options.User.AllowedUserNameCharacters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._@+";
        options.User.RequireUniqueEmail = true;
    });

    services.ConfigureApplicationCookie(options =>
    {
        options.Cookie.HttpOnly = true;
        options.ExpireTimeSpan = System.TimeSpan.FromDays(45);
        options.LoginPath = "/Identity/Account/Login";
        options.AccessDeniedPath = "/Identity/Account/AccessDenied";
        options.SlidingExpiration = true;
    });

如果您无法使用任何默认的密钥持久化方法,还有其他可用的选项,例如将密钥存储在数据库(通过 Entity Framework)、Redis、Azure KeyVault 等服务中

有关详细信息,请参阅 Key Storage Providers