ASP.NET验证滑动到期时间定制票

编程入门 行业动态 更新时间:2024-10-26 12:33:58
本文介绍了ASP.NET验证滑动到期时间定制票的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我用下面的code创造我自己的身份验证票证:

I am creating my own authentication ticket using the following code:

string formsCookieStr = string.Empty; FormsAuthenticationTicket ticket = new FormsAuthenticationTicket( 1, // version username, // user name DateTime.Now, // issue time DateTime.Now.AddMinutes(30), // expires false, // Persistence userRoleData // user data ); formsCookieStr = FormsAuthentication.Encrypt(ticket); HttpCookie FormsCookie = new HttpCookie(FormsAuthentication.FormsCookieName, formsCookieStr); HttpContext.Response.Cookies.Add(FormsCookie);

我要到期成为一个滑动过期 - 每个客户端发送一个请求,那么到期应复位到30分钟的时间。不过,我只是创造了票时,在用户首次登录。ASP.NET会自动保持滑动到期时间对我来说,还是我需要做的事情'手动'来实现滑动过期?

I want the expiration to be a sliding expiration - each time the client sends a request then the expiration should be reset to 30 mins. However, I'm only creating the ticket when the user first logs in. Will ASP.NET automatically keep sliding the expiry time for me, or do I need to do something 'manually' to implement the sliding expiration?

推荐答案

这是在形式配置 web.config中的部分。滑动过期的工作方式是,对每个请求ASP.NET引擎通过增加超时重写身份验证Cookie:

That's configured in the forms section of web.config. The way sliding expiration works is that on each request the ASP.NET engine rewrites the authentication cookie by incrementing the timeout:

<authentication mode="Forms"> <forms loginUrl="~/Account/LogOn" timeout="2880" slidingExpiration="true" /> </authentication>

不过请注意,启用滑动过期是认为在 ASP.NET安全的做法不好的事情之一实践的。

更多推荐

ASP.NET验证滑动到期时间定制票

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

发布评论

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

>www.elefans.com

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