Asp.net KeyRingBasedDataProtector:不可表示的日期时间

Asp.net KeyRingBasedDataProtector:不可表示的日期时间,asp.net,asp.net-mvc,datetime,asp.net-core-mvc,Asp.net,Asp.net Mvc,Datetime,Asp.net Core Mvc,我正在构建的ASPNET5/MVC6/DNX核心站点出现问题。它应该要求所有用户都经过身份验证。它使用EF7作为数据存储,用户帐户/声明是围绕“默认”EF7用户类构建的 我在startup.cs中配置了如下安全性: public void ConfigureServices( IServiceCollection services ) { // Add framework services. services.AddEntityFramework(

我正在构建的ASPNET5/MVC6/DNX核心站点出现问题。它应该要求所有用户都经过身份验证。它使用EF7作为数据存储,用户帐户/声明是围绕“默认”EF7用户类构建的

我在startup.cs中配置了如下安全性:

    public void ConfigureServices( IServiceCollection services )
    {
        // Add framework services.
        services.AddEntityFramework()
            .AddSqlServer()
            .AddDbContext<ApplicationDbContext>(options =>
                options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"]));

        services.AddIdentity<ApplicationUser, IdentityRole>(o =>
        {
            // configure identity options
            o.Password.RequireDigit = false;
            o.Password.RequireLowercase = false;
            o.Password.RequireUppercase = false;
            o.Password.RequireNonLetterOrDigit = false;
            o.Password.RequiredLength = 8;
        })
            .AddEntityFrameworkStores<ApplicationDbContext>()
            .AddDefaultTokenProviders();

        // require authenticated users who have been validated (i.e., have a 'user' claim)
        AuthorizationPolicy authPolicy = new AuthorizationPolicyBuilder()
            .RequireAuthenticatedUser()
            .RequireClaim("user")
            .Build();

        services.AddMvc( x=>
        {
            x.Filters.Add(new AuthorizeFilter(authPolicy));
        });

        // Add application services.
        services.AddTransient<IEmailSender, AuthMessageSender>();
        services.AddTransient<ISmsSender, AuthMessageSender>();

        services.Configure<SiteConfig>(Configuration.GetSection("SiteConfig"));

        services.AddDataProtection();

        // have to avoid setting a file path when we're invoked by dnx
        if( (HostEnvironment != null) && (HostEnvironment.WebRootPath != null ) )
            services.ConfigureDataProtection(configure =>
            {
                string pathToCryptoKeys = Path.Combine(HostEnvironment.WebRootPath, "dp_keys");
                configure.PersistKeysToFileSystem(new DirectoryInfo(pathToCryptoKeys));
                configure.SetDefaultKeyLifetime(TimeSpan.MaxValue);
            });
    }
public void配置服务(IServiceCollection服务)
{
//添加框架服务。
services.AddEntityFramework()
.AddSqlServer()文件
.AddDbContext(选项=>
使用SQLServer(配置[“数据:默认连接:连接字符串]);
服务。附加性(o=>
{
//配置标识选项
o、 Password.RequireDigit=false;
o、 Password.RequireLowercase=false;
o、 Password.RequireUppercase=false;
o、 Password.requireNonletterDigit=false;
o、 Password.RequiredLength=8;
})
.AddEntityFrameworkStores()
.AddDefaultTokenProviders();
//需要经过验证的经过身份验证的用户(即拥有“用户”声明)
AuthorizationPolicy authPolicy=新建AuthorizationPolicyBuilder()
.RequireAuthenticatedUser()文件
.REQUIRE(“用户”)
.Build();
services.AddMvc(x=>
{
x、 Filters.Add(新的AuthorizeFilter(authPolicy));
});
//添加应用程序服务。
services.AddTransient();
services.AddTransient();
services.Configure(Configuration.GetSection(“SiteConfig”);
services.AddDataProtection();
//当dnx调用我们时,必须避免设置文件路径
if((HostenEnvironment!=null)&&(HostenEnvironment.WebRootPath!=null))
services.ConfigureDataProtection(配置=>
{
string pathToCryptoKeys=Path.Combine(HostenEnvironment.WebRootPath,“dp_键”);
configure.persistenkeystems(新的DirectoryInfo(pathToCryptoKeys));
configure.SetDefaultKeyLifetime(TimeSpan.MaxValue);
});
}
该网站负载良好。但是在第一个页面出现之前(应该是登录页面),它会崩溃,并出现以下错误:

处理请求时发生未处理的异常

ArgumentOutOfRangeException:加上或减去的值将导致 不可表示的日期时间。参数名称:t System.DateTime.op_加法(日期时间d,时间跨度t)

CryptographicException:尝试加密时出错 提供了数据。有关更多信息,请参阅内部异常。 Microsoft.AspNet.DataProtection.KeyManagement.KeyRingBasedDataProtector.Protect(字节[]) (纯文本)


看起来我在加密领域配置失败或配置错误。但我不确定是什么。

有没有为这个问题找到解决方案?我遇到了同样的问题:(抱歉,但是已经很久了,我不记得我是否解决了这个问题或者只是删除了一些功能。FWIW,我当前的工作解决方案不使用授权策略。谢谢Mark。我会找到这个问题的解决方案,并让您知道我找到了什么。