ASP.NET - 基于 web.config 中的 sessionState 超时的 Javascript 超时警告
问题:我希望在基于 webconfig sessionState TimeOut 属性的 ac# 代码后面的 asp.net 页面上创建超时警告消息。
web.config 上的代码:
<configuration>
<system.web>
<sessionState timeout="20"></sessionState>
</system.web>
</configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="EchoSignDocumentService10HttpBinding" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="6553600" maxBufferPoolSize="524288" maxReceivedMessageSize="6553600" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="1638400" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="Transport">
<transport clientCredentialType="None" proxyCredentialType="None" realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
<binding name="EchoSignDocumentService10HttpBinding1" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None" realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
</system.serviceModel>
Problem: I am looking to create a time-out warning message on an asp.net page with a c# code behind based off my webconfig sessionState TimeOut Attribute.
Code on web.config:
<configuration>
<system.web>
<sessionState timeout="20"></sessionState>
</system.web>
</configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="EchoSignDocumentService10HttpBinding" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="6553600" maxBufferPoolSize="524288" maxReceivedMessageSize="6553600" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="1638400" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="Transport">
<transport clientCredentialType="None" proxyCredentialType="None" realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
<binding name="EchoSignDocumentService10HttpBinding1" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None" realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
</system.serviceModel>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
伪代码:
setTimeout
传递超时时间(20 * 60))示例代码:
当然,你可以改进通过显示警告弹出窗口甚至确认弹出窗口来客户端显示(而不是显示警报),然后您可以使用它来续订会话。
Pseudo code:
setTimeout
passing the timeout period (20 * 60))Sample code:
Of course, you can improve the client side display (rather than showing an alert) by displaying warning popups or even a confirm popup which you can then use to renew the session.
我之前已经通过在代码隐藏文件中创建一个 Web 方法来检查超时来完成此操作。让您的 Javascript 函数通过 AJAX 获取超时信息并根据情况显示警告。
示例
这是我的代码隐藏中的 Web 方法:
这是我的 Javascript:
所以,这是非常基本的。每 30 秒,我的 Javascript 函数就会使用 ASP.NET 的 PageMethods 对象向我的 Web 方法发送一个 AJAX 请求。它检查回调中的返回值 true(这表明发生了超时),并采取适当的操作。
I've done this before by creating a web method in my code-behind file that checks for the timeout. Have your Javascript function get the timeout information via AJAX and display a warning according.
Example
This is the web method in my code-behind:
And this is my Javascript:
So, this is pretty rudimentary. Every 30 seconds, my Javascript function sends an AJAX request to my web method using ASP.NET's PageMethods object. It checks for a return value of true in the callback, which indicates that a timeout has occurred, and takes the appropriate action.
我无法让 FishbasketGordo 的代码正常工作,因为 Web 方法调用不断将布尔值“false”作为 onsuccess 方法传递。经过大量研究后,我做了以下更改。
I was not able to get FishbasketGordo's code to work because the Web Method call kept passing the Boolean value "false" as the onsuccess method. After much research I made the following changes.
尝试这个解决方案(需要脚本管理器):
Try this solution (requires a script manager):
尝试一下 使用 Jquery 的 Seesion Alert我的博客:
Try This Seesion Alert Using Jquery from my blog:
我在我的 asp.net edit.aspx 页面上使用以下 javascript 代码创建了一条超时警告消息,要求用户在会话超时之前保存数据 x 剩余分钟数:
我将警告消息的频率设置为每个20 分钟,并通过将其作为应用程序设置下的变量来轻松更改,也可以在 web.config 下访问该设置并将其定义为键 (SessionWarning),其值为 20(代表 20 分钟)。
这是我在 web.config 文件中使用的代码:
I created a time-out warning message askign the user to save data before the session times out in x number of remaining minutes using the following javascript code on my asp.net edit.aspx page:
I set the frequency of the warning message to every 20 minutes and made it easy to change by putting it as a variable under the application settings, which is also accessible in the web.config under and defined as a key (SessionWarning) w/ a value to 20 (representing 20 minutes).
Here's the code I used on my web.config file: