ASP.NET2.0 Forms 验证
web.config 配置文件
protected void Button1_Click(object sender, EventArgs e)
{
if (Username.Text.Trim() == "admin" && password.Text.Trim() == "123")
{
FormsAuthentication.RedirectFromLoginPage(Username.Text.Trim(), false);
}
}
1
<location path="ValidateImage.ashx">
2
<system.web>
3
<authorization>
4
<allow users="*"/>
5
</authorization>
6
</system.web>
7
</location>
8
<system.web>
9
<authentication mode="Forms">
10
<forms loginUrl="Default.aspx" name=".ASPXFORMSAUTH"></forms>
11
</authentication>
12
<authorization>
13
<deny users="?"/>
14
</authorization>
15
</system.web>
<location path="ValidateImage.ashx">2
<system.web>3
<authorization>4
<allow users="*"/>5
</authorization>6
</system.web>7
</location>8
<system.web>9
<authentication mode="Forms">10
<forms loginUrl="Default.aspx" name=".ASPXFORMSAUTH"></forms>11
</authentication>12
<authorization>13
<deny users="?"/> 14
</authorization>15
</system.web>
protected void Button1_Click(object sender, EventArgs e)
{
if (Username.Text.Trim() == "admin" && password.Text.Trim() == "123")
{
FormsAuthentication.RedirectFromLoginPage(Username.Text.Trim(), false);
}
} 1
public BasePage()
2
{
3
this.Load += new EventHandler(BasePage_OnLoad);
4
}
5
private void BasePage_OnLoad(object sender, EventArgs e)
6
{
7
Response.Cache.SetNoStore();
8
if (HttpContext.Current.User.Identity.IsAuthenticated)
9
{
10
Page.ClientScript.RegisterClientScriptBlock(GetType(), "提示", string.Format("alert('{0}');", "Yes"), true);
11
}
12
else
13
{
14
Page.ClientScript.RegisterClientScriptBlock(GetType(), "提示", string.Format("alert('{0}');", "NO"), true);
15
}
16
}
public BasePage()2
{3
this.Load += new EventHandler(BasePage_OnLoad);4
}5
private void BasePage_OnLoad(object sender, EventArgs e)6
{7
Response.Cache.SetNoStore();8
if (HttpContext.Current.User.Identity.IsAuthenticated)9
{10
Page.ClientScript.RegisterClientScriptBlock(GetType(), "提示", string.Format("alert('{0}');", "Yes"), true);11
}12
else13
{14
Page.ClientScript.RegisterClientScriptBlock(GetType(), "提示", string.Format("alert('{0}');", "NO"), true);15
}16
}

浙公网安备 33010602011771号