I want to create session timeout
warning popup with timer.
I have included code in master pag
e and it working well just for master page, when i open any page which is link with master then session time start but i want for complete application.
Master page 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>
aspx.cs
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);
}
}
I want when session expire on any page on application then session timeout
warning popup will be show.