手机
当前位置:查字典教程网 >编程开发 >asp.net教程 >ASP.NET 防止用户跳过登陆界面
ASP.NET 防止用户跳过登陆界面
摘要:1.在登陆页面的检查登陆成功代码后添加如下代码Session["UserID"]=txtUserID.Text.Trim();或者Sessi...

1.在登陆页面的检查登陆成功代码后添加如下代码

Session["UserID"] = txtUserID.Text.Trim();

或者

Session["UserID"] = "OK";

例如,在我的 Login.aspx.cs 的登陆按钮响应事件中代码如下:

if (BaseClass.CheckUser(txtUserID.Text.Trim(), txtPwd.Text.Trim()))

{

Session["UserID"] = txtUserID.Text.Trim();

Response.Redirect("Main.aspx");

}

else

{

Response.Write("<script>alert('用户名或密码错误');location='Login.aspx'</script>");

}

2.然后在每个页面的Page_Load的开始处添加如下代码:

if (Session["UserID"] == null || Session["UserID"].ToString() == "")

{

Response.Write("<Script language='javascript'>window.top.location.href='Login.aspx';</Script>");

}

例如在我的 Main.aspx.cs 的Page_Load代码包含如下内容:

protected void Page_Load(object sender, EventArgs e)

{

if (Session["UserID"] == null || Session["UserID"].ToString() == "")

{

Response.Write("<Script language='javascript'>window.top.location.href='Login.aspx';</Script>");

}

if (!IsPostBack)

{

}

}

3.试试看,呵呵 ,,,

【ASP.NET 防止用户跳过登陆界面】相关文章:

ASP.NET MVC 学习5、登陆页面改为SSO验证

ASP.NET中实现获取调用方法名

ASP.NET中利用存储过程实现模糊查询

ASP.NET c#生成随机数

ASP.NET 导出到Excel时保留换行的代码

ASP.NET缓存方法分析和实践示例代码第1/2页

ASP.NET中DataTable,DataSet,DataView的用法小结

ASP.NET简单的文字水印功能

ASP.NET 页面中加添加用户控件的写法

ASP.NET2.0新特性概述

精品推荐
分类导航