1、admins目录访问时转到admins/login.aspx 2、other.aspx访问时转到login.aspx 配置文件设置拒绝other.aspx和admins目录,默认登录页面为login.aspx,并设置允许匿名访问admins/login.aspx】
<configuration> <system.web> <authentication mode="Forms"> <forms loginUrl="login.aspx"> </forms> </authentication> </system.web> <location path="other.aspx"> <system.web> <authorization> <deny users="?"/> </authorization> </system.web> </location> <location path="admins/login.aspx"> <system.web> <authorization> <allow users="?"/> </authorization> </system.web> </location> <location path="admins"> <system.web> <authorization> <deny users="?"/> </authorization> </system.web> </location> </configuration>
在login.aspx页面Page_Load事件里加判断:
string url = Request.QueryString["ReturnUrl"]; if (!string.IsNullOrEmpty(url) && url.StartsWith("/admins/")) { Response.Redirect("admins/login.aspx"); }