I have very basic understanding of JS. I want to practice idle user session timeout. But it should popup warning 20s before Expiry and If user presses continue session it should reset session timeout back to 1 Minute. I have followed this blog to create session. I have seen some tutorials including Tutorial But I don't exactly know how to implement this functionality in my code. Can somebody kindly explain.
My Code:
web.config :
//login.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Login.aspx.cs" Inherits="SessionTimeOut.Login" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<table style="background-color: silver; margin-top: 60px;margin-left:20px;width:18%;height:70%">
<tr>
<td></td>
<td style="font-family: 'Times New Roman', Times, serif; font-weight: bold">Login</td>
</tr>
<tr>
<td>
UserId
</td>
<td>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
</td>
<td>
<asp:TextBox ID="TextBox2" runat="server" TextMode="Password"></asp:TextBox>
</td>
</tr>
<tr>
<td>
Password
</td>
<td>
<asp:Button ID="Button1" runat="server" Text="Login" OnClick="Button1_Click" />
</td>
</tr>
</table>
</form>
</body>
</html>
//login.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace SessionTimeOut
{
public partial class Login : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
Session["LoginUserName"] = Convert.ToString(TextBox1.Text);
Response.Redirect("Welcome.aspx");
}
}
}
//Welcome.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Welcome.aspx.cs" Inherits="SessionTimeOut.Welcome" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body style="background-color:Blue;">
<form id="form1" runat="server" >
<div style="margin-top:20px">
<asp:Button ID="Button1" runat="server" Text="Goto Add User Page"
onclick="Button1_Click" />
</div>
<hr/>
<asp:Label ID="Label1" style="font-family: 'Times New Roman', Times, serif; color:White; font-size: medium; font-weight: bold" runat="server" Text="Label"></asp:Label>
<hr/>
</form>
</body>
</html>
//welcome.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace SessionTimeOut
{
public partial class Welcome : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Label1.Text = "WelCome " + Convert.ToString(Session["LoginUserName"]);
}
protected void Button1_Click(object sender, EventArgs e)
{
Response.Redirect("AddUserDetails.aspx");
}
}
}
//AddUserDetals.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="AddUserDetails.aspx.cs" Inherits="SessionTimeOut.AddUserDetails" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body style="background-color:Blue;">
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" style="font-family: 'Times New Roman', Times, serif; color:White; font-size: medium; font-weight: bold" runat="server" Text="You are on Add User Page"></asp:Label>
<hr />
<asp:Button ID="Button1" runat="server" Text="Back to Welcome Page"
onclick="Button1_Click" />
</div>
</form>
</body>
</html>
//AddUserDetails.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace SessionTimeOut
{
public partial class AddUserDetails : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
Response.Redirect("Welcome.aspx");
}
}
}
Aucun commentaire:
Enregistrer un commentaire