研究了一下asp.net下web验证问题:
web.config:
1.添加字符串
<configuration>
<appSettings>
<add key="con" value="server=.;database=Northwind;uid=sa;pwd=;"></add>
<add key="select" value="select * from customers"></add>
</appSettings>
<connectionStrings />
2.可以身份验证(Forms验证,需要取消iis下的匿名访问)
<authentication mode="Forms">
<forms name="authWeb" loginUrl="login.aspx" protection="All" timeout="60">
<credentials passwordFormat="MD5">
<user name ="laodin" password="6A3B41905BBC11C48877F3968A2F35B6 " />
<user name ="key" password="3C6E0B8A9C15224A8228B9A98CA1531D" />
<user name="0315128" password="01C87986886D691439F14137C36F5D64 " />
</credentials>
</forms>
</authentication>
<authorization>
<deny users="?" />
</authorization>
后台:
protected void Button2_Click(object sender, EventArgs e)
{
if (System.Web.Security.FormsAuthentication.Authenticate(this.TextBox1.Text, this.TextBox2.Text))
{
System.Web.Security.FormsAuthentication.RedirectFromLoginPage(this.TextBox1.Text,true);
}
else
{
Response.Write("错误,BACK");
}
登出删除cookie:
System.Web.Security.FormsAuthentication.SignOut();
产生MD5散列:
Response.Write(System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(this.TextBox3.Text, "MD5"));
3.自定义错误显示,mode不一样.
customErrors mode="RemoteOnly/On/Off" defaultRedirect="error.aspx">
<!--
<error statusCode="403" redirect="NoAccess.htm" />
<error statusCode="404" redirect="FileNotFound.htm" />
-->
</customErrors>
浙公网安备 33010602011771号