【问题标题】:Asp.net Path AccessAsp.net 路径访问
【发布时间】:2017-03-15 08:05:55
【问题描述】:

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

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. 方式不安全?

【问题讨论】:

    标签: asp.net security webforms web-config role


    【解决方案1】:
     <location path="myPage.aspx">
        <system.web>
          <authorization>
            <allow roles="admin"/>
            <deny users="*"/>
          </authorization>
        </system.web>
      </location>
    

    检查此链接: https://weblogs.asp.net/gurusarkar/setting-authorization-rules-for-a-particular-page-or-folder-in-web-config

    【讨论】:

    • 谢谢。我知道,但我想知道哪个更好。
    • 什么更好取决于您的要求。在一个简单的情况下,您应该启用表单身份验证并将 loginUrl 设置为包含登录表单的页面。然后在 web.config 中设置你的授权规则
    猜你喜欢
    • 2013-12-15
    • 2021-04-13
    • 2023-03-22
    • 1970-01-01
    • 2013-05-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多