【问题标题】:ASP.NET 5 Identity 3.0 scalability with CookieAuthentication使用 CookieAuthentication 的 ASP.NET 5 Identity 3.0 可扩展性
【发布时间】:2016-04-20 00:27:03
【问题描述】:

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

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

这是我在 Startup.cs 中的代码

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

谢谢!!

【问题讨论】:

    标签: c# asp.net-core asp.net-identity-3


    【解决方案1】:

    默认情况下,存储在 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 来覆盖序列化/加密逻辑,但这绝对不是推荐的方法。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-12-14
      • 1970-01-01
      • 2016-04-27
      • 1970-01-01
      • 1970-01-01
      • 2016-10-13
      • 2015-07-26
      相关资源
      最近更新 更多