加入收藏 | 设为首页 | 会员中心 | 我要投稿 焦作站长网 (https://www.0391zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > Asp教程 > 正文

ASP.NET 防止用户跳过登陆界面

发布时间:2020-03-13 13:22:02 所属栏目:Asp教程 来源:站长网
导读:在登陆页面的检查登陆成功代码后添加如下代码
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.试试看,呵呵 ,,,

(编辑:焦作站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读