【问题标题】:IIS, denying access to static files; What is wrong with this example?IIS,拒绝访问静态文件;这个例子有什么问题?
【发布时间】:2014-11-26 11:55:59
【问题描述】:

我正在尝试获取默认情况下允许访问的最简单示例,除非对 IIS 中的特定目录进行身份验证,否则拒绝访问以使其正常工作。当你在 Google 周围搜索时,每个人都说这很简单:

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

不知何故,它不适合我。

这是项目结构:

这是 Web.config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.web>
        <authentication mode="Forms">
            <forms loginUrl="~/" />
        </authentication>
        <authorization>
            <!--<deny users="*"/>-->
        </authorization>
    <compilation debug="true" targetFramework="4.5.1" />
    <httpRuntime targetFramework="4.5.1" />
  </system.web>
    <system.webServer>
        <modules runAllManagedModulesForAllRequests="true" />
    </system.webServer>
    <location path="~/pages">
        <system.web>
            <authorization>
                <deny users="?"/>
            </authorization>
        </system.web>
    </location>
</configuration>

目标是允许所有用户访问 index.html 并拒绝访问页面中的所有内容。

这是我的观察:

  • &lt;!--&lt;deny users="*"/&gt;--&gt; 在未注释时有效。
  • 如果没有&lt;modules runAllManagedModulesForAllRequests="true" /&gt;,它根本不起作用。删除它,deny 在任何地方都不起作用。
  • &lt;location path="~/pages"&gt; 中的 deny 不起作用。将路径设置为pagespages/secure.html~/pages/secure.html 也不起作用。

这里有什么问题?

【问题讨论】:

  • 您遇到的具体错误是什么?
  • 没有错误。我不应该能够访问 /secure.html,但我可以。除非我取消注释全局 &lt;deny&gt; 所有用户。拒绝访问特定路径不起作用。
  • 知道了,再看看

标签: asp.net iis web-config forms-authentication static-files


【解决方案1】:

它不喜欢路径 "~/pages" 。以下对我有用

<configuration>
    <system.web>
        <authentication mode="Forms"/>
        <compilation debug="true" targetFramework="4.5.1" />
        <httpRuntime targetFramework="4.5.1" />
    </system.web>
    <system.webServer>
        <modules runAllManagedModulesForAllRequests="true"></modules>
    </system.webServer>

    <!-- note the change below -->
    <location path="pages" >
        <system.web>
            <authorization>
                <deny users="?"/>
            </authorization>
        </system.web>
    </location>
</configuration>

【讨论】:

  • 不知何故这是我没有尝试过的唯一组合。
猜你喜欢
  • 1970-01-01
  • 2013-01-17
  • 1970-01-01
  • 2021-05-01
  • 1970-01-01
  • 2016-02-02
  • 1970-01-01
  • 2014-06-01
  • 1970-01-01
相关资源
最近更新 更多