.NetFrom验证方便的webconfig 配置及前台使用(推荐)

总结一个比较简单的配置方式及前台使用方法

在登陆页面Loing.aspx创建以后,把通过验证要跳转的地址提前创建好,后期会很方便。

1.把Web.config进行简单基础的配置

 <authentication mode="Forms">
      <forms defaultUrl="TaskList.aspx" loginUrl="Loing.aspx">
        <credentials passwordFormat="Clear">
          <user name="admin" password="admin"/>
        </credentials>
      </forms>
    </authentication>
    <authorization>
      <allow users="admin"/>
      <deny users="?"/>
    </authorization>

2.Loing.aspx前台配置

 protected void LoginButton_Click(object sender, EventArgs e)
        {
            if (FormsAuthentication.Authenticate(UserName.Text,Password.Text))
            {
                FormsAuthentication.RedirectFromLoginPage(UserName.Text,true);
            }
            else
            {
                Response.Write("<script>alert('非法进入!');location.href='Loing.aspx';</script>");
            }
        }

很简单,两步走,但是有些单词可能比较长,要经常写和练才能记住。

posted @ 2020-06-18 17:42  Neat帆  阅读(203)  评论(2编辑  收藏  举报