具有CookieAuthentication的ASP.NET 5 Identity 3.0可伸缩性 [英] ASP.NET 5 Identity 3.0 scalability with CookieAuthentication

查看:108
本文介绍了具有CookieAuthentication的ASP.NET 5 Identity 3.0可伸缩性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将ASP.NET 5与MVC6结合使用.我正在使用Identity 3.0,但是我需要知道如何使其与许多Web服务器一起使用.

I'm using ASP.NET 5 with MVC6. I am working with Identity 3.0, but I need to know how to make it works with many webservers.

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

Is possible to store the session in other place? Database? In MVC5 you did that in the web.config, but I don't found information about it in MVC6.

这是我在Startup.cs中的代码

This is my code in Startup.cs

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

谢谢!

推荐答案

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

By default, authentication tickets stored in cookies are self-contained: knowing the encryption key is enough to retrieve the original ticket (there's no store or database involved in this process).

要确保所有服务器都可以读取身份验证cookie,您需要同步它们用于加密和解密身份验证票证的密钥环.如文档所述,可以使用UNC共享来完成此操作:

To make sure your authentication cookies are readable by all your servers, you need to synchronize the key ring they use to encrypt and decrypt authentication tickets. This can be done using an UNC share, as mentioned by the documentation: 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来覆盖序列化/加密逻辑,但这绝对不是推荐的方法.

Alternatively, you could also provide your own TicketDataFormat to override the serialization/encryption logic, but it's definitely not the recommended approach.

这篇关于具有CookieAuthentication的ASP.NET 5 Identity 3.0可伸缩性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆