关于session 的过期跳转问题
系统默认Session的有效时间是二十分钟,用户在这期间,没有任何操作,那么Session就会过期。如果当前操作要用到Session的值那到就会出现错误。
所以我们要在每个页面有做Session的判断。
首先写一个基类:
代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI;//要引用这个DLL
namespace Common
{
public class PageBase : Page
{
protected void Page_Init()
{
if (Session["UserName"] == null)
{
string _path = Request.Path;
//JavaScript的代码负责转到登录页面去
Response.Write(@"<a id='L_a' href='LogOut.aspx' target='_parent'>退出</a>
<script language='javascript' type='text/javascript'>
document.getElementById('L_a').click();</script>");
Response.End();
}
}
}
}
写好基类 那么一切就好简单了。
只需要页面继承基类就可以了,
一句搞定。
public partial class Left : Common.PageBase

浙公网安备 33010602011771号