如果闲置10分钟,如何使页面会话失效 [英] How to expire page session if it is idle for 10 minutes

查看:82
本文介绍了如果闲置10分钟,如何使页面会话失效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果UserHomepage.aspx页面闲置10分钟,我想将其重定向到过期页面(expired.aspx)



然后如果他点击返回按钮用户必须退出然后重定向到主页(Home.aspx)



怎么做



这是我的代码

userHomePage.cs

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

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();
            }
        }
    }

推荐答案

检查用户是否空闲的非常奇怪的方法10分钟,而不是使用会话超时,然后重定向到相应的页面。



打开Web.config文件并将会话超时设置为10分钟,如:

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:
<system.web>  
  <sessionState mode="InProc" timeout="10"/>  
</system.web>  



详情:

C#Corner:会话超时后重定向页面 [ ^ ]


您需要配置会话超时。阅读这些



如果页面会话闲置10分钟,如何使页面会话失效 [ ^ ]



c# - 如何在asp.net 3.5中的会话超时时将用户重定向到默认页面 - Stack Overflow
[ ^ ]
You need to configure session timeout. Read these

How to expire page session if it is idle for 10 minutes[^]

c# - how to redirect user to default page on session time out in asp.net 3.5 - Stack Overflow
[^]


这篇关于如果闲置10分钟,如何使页面会话失效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆