手机
当前位置:查字典教程网 >编程开发 >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中DataTable,DataSet,DataView的用法小结

ASP.NET c#生成随机数

在ASP.NET 中实现单点登录

ASP.NET 2.0中预设的cookie

ASP.NET Dictionary 的基本用法示例介绍

利用ASP.NET技术动态生成HTML页面

ASP.NET编程中经常用到的27个函数集

ASP.NET 运行.bat文件的实现方法

ASP.NET 用户多次登录的解决方法

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

精品推荐
分类导航