<span style="font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: rgb(255, 255, 255);">1、在web.config中的设置</span>
<system.web>
<span style="white-space:pre"> </span>.......
<span style="white-space:pre"> </span>.......
<authentication mode="Forms">
<forms name=".loginAuth"
loginUrl="login.aspx"
defaultUrl="index.aspx"
path="/"
timeout="30">
</forms>
</authentication>
<authorization >
<allow users="*"/>
</authorization>
</system.web>
<location path="adm">
<system.web>
<authorization>
<deny users="?"/>
</authorization>
</system.web>
</location>
访问adm目录的文件要登入权限,自动转到login.aspx的登陆画面中
2、login.aspx判断是否有进入权限
myCommand.CommandText = "SELECT ..... FROM userList WHERE (userName=@userName OR userPhone=@userName) AND userPass=@pass";
myCommand.CommandType = CommandType.Text;
SqlDataAdapter myAdapter = new SqlDataAdapter(myCommand);
DataSet myds = new DataSet();
myAdapter.Fill(myds);
if ( myds.Tables[0].Rows.Count > 0)
{
DataRow myRow = myds.Tables[0].Rows[0];
FormsAuthentication.RedirectFromLoginPage(myRow["userName"].ToString().Trim(), false);
Response.Redirect("~/adm/adminLogin_b.aspx?uName=" + myRow["userName"].ToString().Trim());
}
认证通过则将登入的用户名放到FormsAuthentication中
3、登出
FormsAuthentication.SignOut();