拒绝访问文件夹但允许访问该文件夹内的文件

Deny access to folder but allow access to a file inside that folder

我想拒绝匿名用户访问文件夹 'test' 但排除并允许访问测试文件夹内的文件 'webform1'。为什么这不起作用?

<location path="test">
<system.web>
  <authorization>
    <deny users="?"/>
  </authorization>
</system.web>
</location>
<location path="test/webform1">
<system.web>
  <authorization>
    <allow users="*"/>
  </authorization>
</system.web>

这是一个 link 到示例 webforms 项目 https://github.com/uselesshasid/Whosebug_Question_38597397

这可能是 asp.net 中的一个错误,它在使用友好的 url 时处理授权的方式。

我将 web.config 更改为按文件 url 的版本定义,它起作用了。

<location path="test/webform1">
<system.web>
   <authorization>
     <allow users="*"/>
   </authorization>
</system.web>
<location path="test/webform1.aspx">
<system.web>
   <authorization>
     <allow users="*"/>
   </authorization>
</system.web>