1

我将 ASP.NET 5 与 MVC6 一起使用。我正在使用 Identity 3.0,但我需要知道如何使它与许多网络服务器一起使用。

可以将会话存储在其他地方吗?数据库?在 MVC5 中,您在 web.config 中执行此操作,但我在 MVC6 中没有找到有关它的信息。

这是我在 Startup.cs 中的代码

app.UseCookieAuthentication(options =>
            {
                options.AutomaticAuthenticate = true;
                options.LoginPath = new PathString("/Account/Login");
                options.AutomaticChallenge = true;
            });

谢谢!!

4

1 回答 1

3

默认情况下,存储在 cookie 中的身份验证票证是自包含的:知道加密密钥就足以检索原始票证(此过程中不涉及存储或数据库)。

为了确保所有服务器都可以读取您的身份验证 cookie,您需要同步它们用于加密和解密身份验证票证的密钥环。这可以使用 UNC 共享来完成,如文档所述: http: //docs.asp.net/en/latest/security/data-protection/configuration/overview.html

public void ConfigureServices(IServiceCollection services) {
    services.AddDataProtection();

    services.ConfigureDataProtection(options => {
        options.PersistKeysToFileSystem(new DirectoryInfo(@"\\server\share\directory\"));
    });
}

或者,您也可以提供自己的TicketDataFormat来覆盖序列化/加密逻辑,但这绝对不是推荐的方法。

于 2016-01-14T19:58:43.730 回答