【问题标题】:forms authentication and deny access to all files形成身份验证并拒绝访问所有文件
【发布时间】:2017-11-17 02:41:04
【问题描述】:

我创建了一个带有表单身份验证的“受限”页面,它运行良好。

<authentication mode="Forms">
    <forms loginUrl="login.aspx" defaultUrl="documents.aspx" />
</authentication>

<location path="documents.aspx">
    <system.web>
        <authorization>
            <deny users="?"/>
        </authorization>
    </system.web>
</location>

我想根据此身份验证拒绝访问文件夹及其包含的所有文件。基本上,documents.apsx 有一个可以下载的文档列表。如果我尝试访问 www.mywebsite.com/documents,我会自动重定向到 login.aspx。我在我的 Documents 文件夹中添加了以下 Web.config:

<?xml version="1.0"?>
<configuration>

  <system.web>
    <authorization>
      <deny users="?"/>
    </authorization>
  </system.web>

</configuration>

但是,如果我知道文档的路径,例如 www.mywebsite.com/documents/test.pdf,我可以访问该文件。

我的问题是:如果您未通过身份验证,如何拒绝访问 Document 文件夹中的所有文件?

【问题讨论】:

    标签: asp.net web-config form-authentication


    【解决方案1】:

    将所有文档 PDF 放在一个文件夹中,并对该文件夹设置限制,如下所示:

    <location path="FolderName">
    <system.web>
        <authorization>
            <deny users="?"/>
        </authorization>
    </system.web>
    

    【讨论】:

      猜你喜欢
      • 2019-12-12
      • 2016-03-15
      • 2017-11-28
      • 1970-01-01
      • 2011-01-20
      • 2018-01-06
      • 1970-01-01
      • 2021-03-02
      • 2023-04-06
      相关资源
      最近更新 更多