创建Cookie身份验证 集群验证
MyXmlRepository.cs
实现 IXmlRepository
接口
public class MyXmlRepository : IXmlRepository
{
// 获取所有 XML(物理密钥) 元素
public IReadOnlyCollection<XElement> GetAllElements()
{
// 返回持久化的 XML (物理密钥)
}
// 存储 XML(物理密钥) 数据
public void StoreElement(XElement element, string friendlyName)
{
// 将 XML(物理密钥) 做持久化处理
}
}
配置数据保护官方文档
public void ConfigureServices(IServiceCollection services)
{
//...
// 配置数据保护
services.AddDataProtection()
.SetApplicationName("SharedCookieApp")
.Services.Configure<KeyManagementOptions>(options =>
{
options.XmlRepository = new MyXmlRepository();
});
services.AddAuthentication(options =>
{
options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
})
.AddCookie();
//...
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
// ...
app.UseAuthentication();
//...
}