当会话过期时,我将用户重定向到登录页面。 Login.aspx
是root用户。
我在web.config文件中声明了这样的路径。
<forms name=".FormsAuth" loginUrl="~/Login.aspx" protection="All"
slidingExpiration="false" requireSSL="false" >
它适用于所有根.aspx
页面。但它不适用于像Reporting\report.aspx
这样的子文件夹页面。
那么如何管理root .aspx页面和子文件夹.aspx页面的重定向页面(Login.aspx)?
答案 0 :(得分:3)
检查您的配置。在我看来,您的标签表单未正确关闭。 如果你有这两个部分,它必须工作:
<authentication mode="Forms">
<forms name=".FormsAuth" loginUrl="~/Login.aspx" protection="All" slidingExpiration="false" requireSSL="false" />
</authentication>
<authorization>
<deny users="?"/>
</authorization>
您可以找到示例应用here。
答案 1 :(得分:0)
默认情况下,名为secure和admin的目录是受保护的唯一目录 你需要使用下面的方法手动保护你想要的导演:
<location path="secure">
<system.web>
<authorization>
<deny users="?"/>
</authorization>
</system.web>
</location>
答案 2 :(得分:0)
所有子文件夹都必须有自己的web.config文件,拒绝匿名用户访问,例如:
<configuration>
<system.web>
<authorization>
<deny users="?" /> <!--Deny all Anonymous (not logged in) users-->
<allow roles="admin,manager,cservice"/> <!--Permit users in these roles-->
<deny users="*"/> <!--Deny all users-->
</authorization>
</system.web>
</configuration>
答案 3 :(得分:0)
您也可以尝试使用
System.Web.Security.FormsAuthentication.RedirectToLoginPage();
如果您正在使用response.redirect或server.transer直接重定向,那么会重定向到配置中设置的登录页面
答案 4 :(得分:0)
点击此页面: http://msdn.microsoft.com/en-us/library/xdt4thhy(v=vs.100).aspx
以下是设置表单身份验证的基础知识:
的web.config:
<system.web>
<authentication mode="Forms">
<forms loginUrl="logon.aspx" name=".ASPXFORMSAUTH">
</forms>
</authentication>
<authorization>
<deny users="?" />
</authorization>
</system.web>
登录页面:
<script runat="server">
void Logon_Click(object sender, EventArgs e)
{
if ((UserEmail.Text == "jchen@contoso.com") &&
(UserPass.Text == "37Yj*99Ps"))
{
FormsAuthentication.RedirectFromLoginPage
(UserEmail.Text, Persist.Checked);
}
else
{
Msg.Text = "Invalid credentials. Please try again.";
}
}
</script>
退出页面:
<script runat="server">
void Page_Load(object sender, EventArgs e)
{
Welcome.Text = "Hello, " + Context.User.Identity.Name;
}
void Signout_Click(object sender, EventArgs e)
{
FormsAuthentication.SignOut();
Response.Redirect("Logon.aspx");
}
</script>