Asp.net路径访问

Asp.net路径访问,asp.net,security,webforms,web-config,role,Asp.net,Security,Webforms,Web Config,Role,我想知道哪种方式更安全地拒绝页面访问。我知道其中一种方式用于文件夹访问。我不需要文件夹 1。方式 <location path="xfile"> <system.web> <authorization> <allow roles="admin"/> <deny users="*"/> </authorization> </system.web&g

我想知道哪种方式更安全地拒绝页面访问。我知道其中一种方式用于文件夹访问。我不需要文件夹

1。方式

 <location path="xfile">
    <system.web>
      <authorization>
        <allow roles="admin"/>
        <deny users="*"/>
      </authorization>
    </system.web>
  </location>
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。道路不安全?


 <location path="myPage.aspx">
    <system.web>
      <authorization>
        <allow roles="admin"/>
        <deny users="*"/>
      </authorization>
    </system.web>
  </location>

谢谢。我知道这一点,但我想知道哪一个更好。什么更好取决于您的要求。在一个简单的情况下,您应该启用表单身份验证,并将loginUrl设置为包含登录表单的页面。然后在web.config中设置授权规则