利用Page事件进行统一身份验证
创建一个名为BasePage的类,继承System.Web.UI.Page
public class BasePage:System.Web.UI.Page
{
public BasePage()
{
this.Load += new EventHandler(BasePage_Load);
}
void BasePage_Load(object sender, EventArgs e)
{
if (Session["usernum"]==null)
{
Response.Write("<script languge='javascript'>alert('离线时间过长');
window.location.href='Login.aspx'</script>");
// 在复杂的框架页面中,用此法可以跳到框架最顶部,从而关闭窗口
Response.Write("<script languge='javascript'>alert('离线时间过长');
top.location.href='Login.aspx'</script>");
Response.End();
}
}
}
其他的后台页面直接继承BasePage即可。
如:
public partial class ManagerFilesClass :BasePage
{
IFile newIFile = new FileService();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Bind();
}
}
private void Bind()
{
this.GridView1.DataSource = newIFile.ReadAllFileIntheDirectory("课程申请").ToList();
this.GridView1.DataBind();
}
/// <summary>
/// 分页
/// </summary>
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
this.GridView1.PageIndex = e.NewPageIndex;
Bind();
}
}
大家看到我把Response.End()加红。为毛?
①请参看我的一篇博客https://blog.sina.com.cn/s/blog_67aaf4440100ms17.html
②
看到没。该页便停止执行!这样如果该页有用到session["usernum"]也不会报错了!
最后更新:2017-04-02 22:16:08
上一篇:
ASP.NET中Get和Post的用法
下一篇:
android listview仿iphone特效(下拉(下冲)或底部往上拉(上冲)有一个弹性回退)
jlink烧写Nor Flash时出错正确解决方法汇总:PC of target system has unexpected value after programming
sql server2005里导入bak文件
Java连接mysql的程序
Spring中的注解
ibatis中传递多个参数
神经网络能解决所有问题吗?
6款可替代Reddit最佳开源免费方案
网络安全法解读之网络数据安全与SSL证书
Web Service 使用分布式事务出错(OLE DB provider 'SQLOLEDB'无法启动分布式事务)
【好书推荐】适合开发者学习DevOps的5本好书