0
我想知道哪种方式更安全地拒绝页面访问。我知道其中的一个文件夹访问。我不需要文件夹。Asp.net路径访问
1路
<location path="xfile">
<system.web>
<authorization>
<allow roles="admin"/>
<deny users="*"/>
</authorization>
</system.web>
</location>
或 2路
protected void Page_Load(object sender, EventArgs e)
{
if (!this.Page.User.Identity.IsAuthenticated)
{
Response.Redirect("/Login");
}
else
{
if (User.IsInRole("admin"))
{
// my action
}
else
{
Response.Redirect("/");
}
}
}
还得我用文件夹的安全性? 或2.方法是不安全的?
谢谢,我知道这一点,但我想学哪一个更好。 – serdar
更好的是取决于你有什么要求。在一个简单的情况下,您应该启用表单身份验证并将loginUrl设置为包含登录表单的页面。然后在web.config中设置授权规则 –