ASP.NET Core 中的 Cookie 身份验证过早过期

编程入门 行业动态 更新时间:2024-10-28 13:22:22
本文介绍了ASP.NET Core 中的 Cookie 身份验证过早过期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个 ASP.NET Core 1.1.2 项目,我在其中使用了 cookie 身份验证.我遇到了一个问题,提示用户在闲置一小时或更短时间后重新登录并丢失工作.下面的代码是我在 Startup.cs 的配置函数中使用的代码来设置它,据我所知,它应该在至少 8 小时后过期.顺便说一句,ProjectProcessFlow 只是项目的名称.

app.UseCookieAuthentication(new CookieAuthenticationOptions(){AuthenticationScheme = "ProjectProcessFlow",LoginPath = new PathString("/Account/Login/"),过期时间跨度 = 新时间跨度(8, 0, 0),SlidingExpiration = 真,自动身份验证 = 真,自动挑战 = 真});

我在 NuGet 中包含了 Microsoft.AspNetCore.Authentication.Cookies v1.1.2.我需要做什么才能让登录到期在预期的时间发生?

附加信息:

我发现当超时发生并要求用户再次登录时,服务器上的事件查看器中记录了一条警告,说找不到项目下的日志文件夹.所以我创建了那个文件夹,然后等待超时再次发生.发生这种情况时,会在该文件夹中创建一个包含以下内容的日志文件:

托管环境:生产内容根路径:C:inetpubwwwrootSprout现在听:localhost:13423应用程序启动.按 Ctrl+C 关闭.

当我重复这个过程时,发生了同样的事情,只是在localhost:"之后出现了不同的数字.我应该提到项目名称是 ProjectProcessFlow,但 URL 以 Sprout 结尾.

解决方案

用户在闲置一小时后被提示重新登录或更少,并失去工作.

我有类似的

I have a ASP.NET Core 1.1.2 project in which I am using cookie authentication. I am having a problem where users are being prompted to log back in after being idle for an hour or less, and losing work. The code below is what I'm using in the Configure function in Startup.cs to set this up and from what I can tell, it should expire after at least 8 hours. BTW, ProjectProcessFlow is just the name of the project.

app.UseCookieAuthentication(new CookieAuthenticationOptions() { AuthenticationScheme = "ProjectProcessFlow", LoginPath = new PathString("/Account/Login/"), ExpireTimeSpan = new TimeSpan(8, 0, 0), SlidingExpiration = true, AutomaticAuthenticate = true, AutomaticChallenge = true });

I am including Microsoft.AspNetCore.Authentication.Cookies v1.1.2 in NuGet. What do I need to do to get the login expiration to happen at the expected time?

Additional Information:

I found that when the timeout happened and the user was asked to login again, a warning was recorded in the Event Viewer on the server that it couldn't find the logs folder under the project. So I created that folder, and waited for the timeout to happen again. When that happened, a log file was created in that folder that contained this:

Hosting environment: Production Content root path: C:inetpubwwwrootSprout Now listening on: localhost:13423 Application started. Press Ctrl+C to shut down.

When I repeated this process, the same thing happened, except that a different number appeared after "localhost:". I should mention that the project name is ProjectProcessFlow, but the URL ends in Sprout.

解决方案

users are being prompted to log back in after being idle for an hour or less, and loosing work.

I have similar configuration, but it works fine for me.

One thing I can think of is you cannot let web server idle for 20 minutes. IIS's app pool default idle time-out is 20 minutes (I could not say for other Linux web server).

So you could either set longer app pool time-out (0 for infinity), or ping every 5 minutes from external service like Monitis.

更多推荐

ASP.NET Core 中的 Cookie 身份验证过早过期

本文发布于:2023-11-09 22:34:19,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1573613.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:身份验证   NET   ASP   Cookie   Core

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!