ASP.NET登录身份验证 一

reference:
http://blog.csdn.net/haojialin/archive/2006/01/13/578869.aspx

新建一个vs2005 web项目,修改web.config下面的authentication / authorization 节点

    <authentication mode="Forms">
      
<forms loginUrl="Login.aspx" name=".ASPXAUTH"></forms>
    
</authentication>
    
<authorization>
      
<deny users="?"></deny>
    
</authorization>

新建2个页面:
Login.aspx
页面添加2个textbox,1个button,后台添加buttonclick事件:
    protected void Button1_Click(object sender, EventArgs e)
    {
        
if (this.Txt_UserName.Text == "Admin" && this.Txt_Password.Text == "123456")
        {
            System.Web.Security.FormsAuthentication.RedirectFromLoginPage(
this.Txt_UserName.Text, false);
        }
    }

Default.aspx
在页面添加一个button,后台添加一个事件:
    protected void Button1_Click(object sender, EventArgs e)
    {
        System.Web.Security.FormsAuthentication.SignOut();
        Server.Transfer(
"Login.aspx");
    }
原文地址:https://www.cnblogs.com/zc22/p/958492.html