1.Login.cs部分
protected void btnSubmit_Click(object sender, EventArgs e) { if (FormsAuthentication.Authenticate(txtUsername.Text, txtPassword.Text)) { FormsAuthentication.RedirectFromLoginPage(txtUsername.Text, true);
}
else { Response.Write("error"); } }
2.web.config中
<system.web> <authentication mode="Forms"> <forms name="222" loginUrl="Login.aspx" path="/"> <!--此处name,password 的格式必须与passwordFormat格式一致,不然前面的识别不了--> <credentials passwordFormat="Clear"> <user name="123" password="123"/> </credentials> </forms> </authentication> <authorization> <deny users="?"/> </authorization>
</system.web>
3.得到存储在web.config中的加密值
string str = FormsAuthentication.HashPasswordForStoringInConfigFile(txtPassword.Text, "Sha1");
转载于:https://www.cnblogs.com/deepwishly/archive/2010/03/17/2551275.html