日期:2014-05-18  浏览次数:20491 次

在那里可以设置session timeout?
在任何一个页面随便做一个操作,比如点击操作。然后等20分钟,这个seesion就认为是timeout了并且跳转到timeout.aspx的页面。请问怎么做?

------解决方案--------------------
在Web.Config里设
< sessionState mode="Off|InProc|StateServer|SQLServer" 
cookieless="true|false" 
timeout="number of minutes" 
stateConnectionString="tcpip=server:port" 
sqlConnectionString="sql connection string" 
stateNetworkTimeout="number of seconds" 
/>
------解决方案--------------------
探讨

在Web.Config里设
< sessionState mode="Off|InProc|StateServer|SQLServer"
cookieless="true|false"
timeout="number of minutes"
stateConnectionString="tcpip……

------解决方案--------------------

判断session是否过期,你可以在母版页中Page_Load、或者在一个自己写页面基类中(大家一般都会命名为PageBase,让其他页面继承PageBase)的Init_Page中判断session是否过期,如果过期则跳转到timeout.aspx 页面就是了


默认session过期时间是20分钟,可以更改web.config配置

<system.web>
<sessionState timeout="20"> timeout 以分钟为单位
</sessionState>
...
------解决方案--------------------
我个人的建议:重载Page_Load事件

C# code


//重写Page基类的OnLoad事件方法
        protected override void OnLoad(EventArgs e)
        {
            //测试
            //Session.RemoveAll();
            try
            {
                if (base.Session["user"] == null || base.Session["user"].ToString().Equals(""))
                {
                    this.ClientScript.RegisterStartupScript(GetType(), "", "<script language=javascript>top.location.href='../../Login.aspx'</script>");
                    //Response.Write("<script language=javascript>top.location.href='../../Login.aspx'</script>");
                }
                else {
                    base.OnLoad(e);
                }
            }
            catch (Exception)
            {

                throw;
            }