对根目录下xianzhi文件夹进行权限设置 想要打开该文件夹下的任何文件必须通过login.aspx页面
<system.web>
<authentication mode="Forms"><!--<forms loginUrl= "login.aspx " protection= "None " timeout= "60"/>-->
<forms loginUrl="login.aspx" protection="All" timeout="200" path="~/xianzhi"></forms>
</authentication>
</system.web>
<location path= "xianzhi">
<system.web>
<authorization>
<deny users= "? "/>
</authorization>
</system.web>
</location>
在 login.aspx验证登录用户
string name = Request["username"];
string pwd = Request["password"];
string sql = "select count(id) from loginipfo where loginname='" + name + "' and loginpwd='" + pwd + "'";
if (Convert.ToInt32(DbHelper.ExecuteScalar(sql)) > 0)
{
Session["name"] = name;
FormsAuthentication.RedirectFromLoginPage(Convert.ToString(Request["username"]), true);
删除用户票据
//FormsAuthentication.SignOut();
重新定向到登陆页面
//FormsAuthentication.RedirectToLoginPage();
}
else
{
Page.ClientScript.RegisterStartupScript(Page.GetType(), "", "<script>alert('账号或者密码错误')</script>");
}