C# 如何显示完整应用程序的会话超时警告弹出窗口
我想创建带有计时器的C# 如何显示完整应用程序的会话超时警告弹出窗口,c#,asp.net,C#,Asp.net,我想创建带有计时器的会话超时警告弹出窗口 我已经在master page中包含了代码,它只适用于母版页,当我打开任何与母版链接的页面时,会话时间开始,但我需要完整的应用程序 母版页aspx <script> function SessionExpireAlert(timeout) { var seconds = timeout / 1000; document.getElementsByName("secondsIdle").inn
会话超时
警告弹出窗口
我已经在master pag
e中包含了代码,它只适用于母版页,当我打开任何与母版链接的页面时,会话时间开始,但我需要完整的应用程序
母版页aspx
<script>
function SessionExpireAlert(timeout) {
var seconds = timeout / 1000;
document.getElementsByName("secondsIdle").innerHTML = seconds;
document.getElementsByName("seconds").innerHTML = seconds;
setInterval(function () {
seconds--;
document.getElementById("seconds").innerHTML = seconds;
document.getElementById("secondsIdle").innerHTML = seconds;
}, 1000);
setTimeout(function () {
//Show Popup before 20 seconds of timeout.
$find("mpeTimeout").show();
}, timeout - 20 * 1000);
setTimeout(function () {
window.location.href = "/WebForm5.aspx";
}, timeout);
return false;
};
function ResetSession() {
//Redirect to refresh Session.
window.location = "/WebForm5.aspx";
}
</script>
<form runat="server" novalidate="" role="form" class="form-horizontal">
<asp:LinkButton ID="lnkFake" runat="server"/>
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:ModalPopupExtender ID="mpeTimeout" BehaviorID="mpeTimeout" runat="server"
PopupControlID="pnlPopup" TargetControlID="lnkFake" OkControlID="btnYes" CancelControlID="btnNo" BackgroundCssClass="modalBackground" OnOkScript="ResetSession()">
</asp:ModalPopupExtender>
<asp:Panel ID="pnlPopup" runat="server" CssClass="modalPopup" Style="text-align: center" BorderColor="#cee2e5" BorderStyle="Solid" BackColor="white" class="header">
<asp:Label ID="Label1" runat="server" BackColor="#cee2e5" Font-Bold="True" Text="Session Expiry Alert" Font-Size="Large" ForeColor="DarkBlue" Style="margin-top: 0px" Width="363px" Visible="true"></asp:Label>
<br />
<asp:Label ID="Label2" runat="server" style="color:black;font-size:16px;" Text="Your Session will expire in"></asp:Label><span style="color:red;font-size:20px;" id="seconds"></span> <asp:Label ID="Label3" runat="server" style="color:black;font-size:16px;" Text=" Seconds"></asp:Label>
<br />
<div class="footer">
<asp:Button ID="btnYes" runat="server" BackColor="Red" ForeColor="White" BorderColor="White" BorderWidth="1px" Text="Logoff" CssClass="yes" />
<asp:Button ID="btnNo" runat="server" BackColor="Green" BorderColor="White" ForeColor="White" BorderWidth="1px" Text="Continue" CssClass="no" />
</div>
</asp:Panel>
<asp:ContentPlaceHolder ID="body" runat="server">
</asp:ContentPlaceHolder>
</form>
我想在应用程序的任何页面上,当会话过期时,会显示
会话超时
警告弹出窗口。您看到了吗?该线程中也有更多的链接。感谢您的回复,请让我知道,这是完整的应用程序的工作,还是这只是一个页面?
protected void Page_Load(object sender, EventArgs e)
{
Response.Cache.SetCacheability(HttpCacheability.NoCache);
if (!IsPostBack)
{
Session["Reset"] = true;
Configuration config = WebConfigurationManager.OpenWebConfiguration("~/Web.Config");
SessionStateSection section = (SessionStateSection)config.GetSection("system.web/sessionState");
int timeout = (int)section.Timeout.TotalMinutes * 1000; //I change the timeout value to 25 seconds
Page.ClientScript.RegisterStartupScript(this.GetType(), "SessionAlert", "SessionExpireAlert(" + timeout + ");", true);
}
}