Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 未设置Asp标识CookieAuthenticationOptions ExpireTimeSpan_Asp.net_Cookies_Asp.net Identity_Asp.net Identity 2 - Fatal编程技术网

Asp.net 未设置Asp标识CookieAuthenticationOptions ExpireTimeSpan

Asp.net 未设置Asp标识CookieAuthenticationOptions ExpireTimeSpan,asp.net,cookies,asp.net-identity,asp.net-identity-2,Asp.net,Cookies,Asp.net Identity,Asp.net Identity 2,我正在使用ASP.NET标识,在Startup.Auth中有以下内容 app.UseCookieAuthentication(new CookieAuthenticationOptions { AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie, LoginPath = new PathString("/Account/Login"),

我正在使用ASP.NET标识,在Startup.Auth中有以下内容

app.UseCookieAuthentication(new CookieAuthenticationOptions
        {
            AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
            LoginPath = new PathString("/Account/Login"),
            ExpireTimeSpan = TimeSpan.FromDays(30),
            SlidingExpiration = false,
            Provider = new CookieAuthenticationProvider
            {
               OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, User, int>(
                    validateInterval: TimeSpan.FromMinutes(5),
                    regenerateIdentityCallback: (manager, user) =>
                        user.GenerateUserIdentityAsync(manager),
                    getUserIdCallback: (id) => (id.GetUserId<int>()))
            } 
        });
app.UseCookieAuthentication(新的CookieAuthenticationOptions
{
AuthenticationType=DefaultAuthenticationTypes.ApplicationOkie,
LoginPath=新路径字符串(“/Account/Login”),
ExpireTimeSpan=时间跨度从天(30),
slidengexpiration=false,
Provider=新CookieAuthenticationProvider
{
OnValidateIdentity=SecurityStampValidator.OnValidateIdentity,默认为14天。在更改ExpireTimeSpan之前,我已确保删除所有现有cookie

CookieAuthenticationOptions是Microsoft.Owin.Security.Cookies命名空间的一部分,我的dll版本为3.0.0.0

我还尝试将FromDays值设置为十进制,如中所述。这也不起作用

任何关于如何解决这件事的建议都将不胜感激。谢谢

更新:我启用了ASP.NET身份双因素身份验证,包括带有“记住我”复选框的用户名和密码登录页面以及带有“记住浏览器”的电话代码验证页面复选框。当我选中两个“记住”复选框时,cookie过期时间设置为14天,即使我将其设置为30天。当我选中第一个“记住”复选框(用户名和密码)时,cookie过期时间设置为我指定的值


所以看起来“记住浏览器”覆盖了ExpireTimeSpan属性值。不幸的是,我想要“记住浏览器”30天后过期。两周的时间太长,不必重新输入我的电话号码。顺便说一句,我遇到此问题的原因是,如果不选中这两个记住复选框,我无法使记住浏览器cookie持续通过浏览器会话,如此stackoverflow问题中所述。

尝试更改cookie的名称。
app.UseCookieAuthentication(新CookieAuthenticationOptions{CookieName=“new name”,…});