asp.net – Session Timeout .NET
发布时间:2021-03-31 03:16:22 所属栏目:asp.Net 来源:互联网
导读:我搜索了但是我找不到这个问题的具体答案. 在会话到期之前,如何在服务器中获得剩余时间? 我的会话设置: //超时,例如10分钟. authentication mode=Forms forms name=.ASPXAUTH_External loginUrl=Authentication/Unauthorized.aspx protection=All timeout=1
我搜索了但是我找不到这个问题的具体答案.
//超时,例如10分钟. <authentication mode="Forms"> <forms name=".ASPXAUTH_External" loginUrl="Authentication/Unauthorized.aspx" protection="All" timeout="10" path="/" slidingExpiration="true" defaultUrl="~/Pages/home.aspx" cookieless="UseDeviceProfile" enableCrossAppRedirects="false"/> </authentication> <sessionState mode="InProc" timeout="10"> </sessionState> 我得到初始值(它会得到10 * 60 = 600秒): SessionStateSection sessionSection = (SessionStateSection)WebConfigurationManager.GetSection("system.web/sessionState"); countdown.Text = sessionSection.Timeout.TotalSeconds.ToString(); 但是当会话时间少于一半时,用户会做一些动作.我得到初始值600,但它不等于左会话时间,因为“slidingExpiration”增加了一些时间(我不知道多少),但不会将会话剩余时间重置为开始10分钟. 如何在到期前获得剩余的会话时间? 解决方法我发现会话到期的时间我可以这样:DateTime dateNow = DateTime.Now; if (HttpContext.Current.User.Identity is FormsIdentity) { HttpCookie authCookie = this.Context.Request.Cookies[FormsAuthentication.FormsCookieName]; FormsAuthenticationTicket authTicket = FormsAuthentication.Decrypt(authCookie.Value); double leftSeconds = (authTicket.Expiration - dateNow).TotalSeconds; // Control in MasterPage,where I setting value ant then taking for JavaSript to CountDown message countdown.Text = leftSeconds > 0 ? leftSeconds.ToString() : "0"; } (编辑:4S站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net-mvc – 如果用户在int字段中放入非数字字符串,则自
- asp.net – Mocking HttpContext不起作用
- 有没有办法加快asp.net中的编辑 – 编译 – 调试周期?
- asp.net读取excel文件的三种方法示例
- asp.net – 有没有一个原因,cshtml不受欢迎
- asp.net-mvc-routing – @ Url.Action获取?附加长度= 2
- asp.net-mvc – Url.Action生成查询字符串,以任何方式生成完
- 序列化 – Newtonsoft中的TypeNameHandling需要$type作为第
- asp.net – 在客户端启用/禁用RequiredValidator /不启动Cu
- Plone和Asp.Net集成
推荐文章
站长推荐
热点阅读