一、使用Form认证的一般设置
<!--Form认证设置Start-->
<authentication mode="Forms">
<forms name=".FrameWork" defaultUrl="Default.aspx" loginUrl="Login.aspx" enableCrossAppRedirects="true" path="/"></forms>
</authentication>
<authorization>
<deny users="?"/>
<!--allow users="*"/-->
</authorization>
<!--Form认证设置End-->
以上在登录站点时将不允许匿名登录。
二、一般目录可匿名访问的文件
可在configuration节点内做如下设置:
<!-- 排除不需要验证的目录或文件-->
<location path="Messages.aspx">
<system.web>
<authorization>
<allow users="*"/>
</authorization>
</system.web>
</location>
三、转网友介绍的方法,比较简单易懂
登录时,如下操作:
(1)
private void Btn_Login_Click(object sender, System.EventArgs e)
{
if(this.Txt_UserName.Text=="Admin" && this.Txt_Password.Text=="123456")
{
System.Web.Security.FormsAuthentication.RedirectFromLoginPage(this.Txt_UserName.Text,false);
}
}
(2)
private void Btn_Login_Click(object sender, System.EventArgs e)
{
if(this.Txt_UserName.Text=="Admin" && this.Txt_Password.Text=="123456")
{
System.Web.Security.FormsAuthentication.SetAuthCookie(this.Txt_UserName.Text,false);
Response.Redirect("Default.aspx");
}
}
以上两种都可发放验证后的Cookie,即通过验证,区别:
共2页 1 2






