Click here to Skip to main content
15,915,160 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
if a UserHomepage.aspx page is idle for 10 minutes , i want to redirect that to expired page(expired.aspx)

and then if he click back button user has to logged out then redirect to home page(Home.aspx)

how to do this

this is my code
userHomePage.cs
C#
protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            BindGrid();
        }
    }

    private void BindGrid()
    {
        string username = Session["new"].ToString();
        string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
        using (SqlConnection con = new SqlConnection(constr))
        {
            using (SqlCommand cmd = new SqlCommand())
            {
                cmd.CommandText = "select Id,UserName,DocumentType,FormType,Name,Description from tblFiles where UserName ='" + username + "'";
                cmd.Connection = con;
                con.Open();
                GridView1.DataSource = cmd.ExecuteReader();
                GridView1.DataBind();
                con.Close();
            }
        }
    }
Posted
Updated 11-Jan-16 21:17pm
v2
Comments
Afzaal Ahmad Zeeshan 12-Jan-16 2:40am    
Sessions do not worry about idle-ness of a user. They can however, exist for a time span. But they won't spy on the user's keystrokes and mouse usage.

Its very weird approach to check if user is idle for 10 minutes, rather than use session timeout and then redirect to corresponding page.

Open the Web.config file and set the Session Timeout to 10 minutes like:
XML
<system.web>  
  <sessionState mode="InProc" timeout="10"/>  
</system.web>  

Details:
C# Corner : Redirect Page After Session Time Out[^]
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900