Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/14.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.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 mvc ASP.NET Identity 2.0随机注销_Asp.net Mvc_Asp.net Web Api_Asp.net Identity_Owin - Fatal编程技术网

Asp.net mvc ASP.NET Identity 2.0随机注销

Asp.net mvc ASP.NET Identity 2.0随机注销,asp.net-mvc,asp.net-web-api,asp.net-identity,owin,Asp.net Mvc,Asp.net Web Api,Asp.net Identity,Owin,我最近开始将我的一个项目从我自己开发的身份验证更改为asp.net identity 2。我有一个问题,虽然这是影响用户。在开发或生产过程中,出于这样或那样的原因,它似乎在没有实际模式或解释的情况下让人们退出 我只使用常规的CookieAuthentication,在数据库中使用自定义的身份表和自定义的UserManager和RoleManager,这样我就可以使用Int32来代替字符串,非常简单 这是我在启动文件中使用的配置 app.UseCookieAuthenticatio

我最近开始将我的一个项目从我自己开发的身份验证更改为asp.net identity 2。我有一个问题,虽然这是影响用户。在开发或生产过程中,出于这样或那样的原因,它似乎在没有实际模式或解释的情况下让人们退出

我只使用常规的
CookieAuthentication
,在数据库中使用自定义的身份表和自定义的UserManager和RoleManager,这样我就可以使用Int32来代替字符串,非常简单

这是我在启动文件中使用的配置

        app.UseCookieAuthentication(new CookieAuthenticationOptions
        {
            AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
            LoginPath = new PathString("/Account/Login"),
            SlidingExpiration = true,
            ExpireTimeSpan = TimeSpan.FromHours(1),
            Provider = new CookieAuthenticationProvider
            {
                OnApplyRedirect = ctx => 
                {
                    if (!ctx.Request.Path.StartsWithSegments(new PathString("/api")) && !ctx.Request.Path.StartsWithSegments(new PathString("/service")))
                    {
                        ctx.Response.Redirect(ctx.RedirectUri);
                    }
                },
                OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<CustomUserManager, WebAccount, int>
                (
                     validateInterval: TimeSpan.FromMinutes(30),
                     regenerateIdentityCallback: (manager, user) => user.GenerateUserIdentityAsync(manager),
                     getUserIdCallback: (id) => (Int32.Parse(id.GetUserId()))
                )
            }
        });
app.UseCookieAuthentication(新的CookieAuthenticationOptions
{
AuthenticationType=DefaultAuthenticationTypes.ApplicationOkie,
LoginPath=新路径字符串(“/Account/Login”),
slidengexpiration=true,
ExpireTimeSpan=从小时(1)开始的时间跨度,
Provider=新CookieAuthenticationProvider
{
OnApplyRedirect=ctx=>
{
如果(!ctx.Request.Path.StartsWithSegments(新路径字符串(“/api”))和&!ctx.Request.Path.StartsWithSegments(新路径字符串(“/service”))
{
响应重定向(ctx.RedirectUri);
}
},
OnValidateIdentity=SecurityStampValidator.OnValidateIdentity
(
validateInterval:TimeSpan.FromMinutes(30),
regenerateIdentityCallback:(管理器,用户)=>user.GenerateUserIdentityAsync(管理器),
getUserIdCallback:(id)=>(Int32.Parse(id.GetUserId())
)
}
});
我看到人们通过表单编辑一些数据,从加载表单到单击保存,他们已经注销并重定向到登录页面,丢失了更改

我不太明白为什么它会这样做,如果有人能透露一些信息,我将不胜感激


提前谢谢

您的页面上是否存在因未通过身份验证而被踢出的请求(例如,图像请求)(例如,在获取页面后但在发布表单之前是否已删除cookie)。如果您遇到随机ish注销,它几乎可以是任何与身份验证本身无关的东西。您需要通过在不同的位置添加日志进行调试(例如,您是否有可能被错误调用的注销功能?),检查服务器日志/IIS日志以及所有这些内容。这听起来像是大海捞针,但你需要首先确定大海捞针:)是的,我已经检查过一些地方,可能有逻辑让人们注销,但没有任何东西可以让人们注销,比如说他们只是被重定向到另一个页面。我只是想,在使用asp identity之前,它可以工作,那么一定与此有关,我会继续挖掘并设置更多日志记录,看看在此期间是否可以找到其他内容:-)403状态响应是否有可能触发identity注销用户?可能是