KeyRingBasedDataProtector:不可代表的DateTime

时间:2016-02-02 20:17:26

标签: 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()
            .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);
            });
    }

网站加载正常。但在出现第一页(应该是登录页面)之前,它会崩溃并出现以下错误:

  

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

     

ArgumentOutOfRangeException:增加或减去的值导致   不可表示的DateTime。参数名称:t   System.DateTime.op_Addition(DateTime d,TimeSpan t)

     

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

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

0 个答案:

没有答案