【问题标题】:IIS7, web.config to allow only static file handler in directory /uploads of websiteIIS7,web.config 只允许在网站的 /uploads 目录中使用静态文件处理程序
【发布时间】:2022-02-02 10:10:15
【问题描述】:

如果可能的话,我如何修改我的 web.config 以使子目录成为静态文件 - 里面的文件只会作为静态文件处理,即使它的名称是“aspx”或其他名称? 谢谢。

【问题讨论】:

  • 为什么不阻止.as?x 上传?
  • 因为除了 .as?x 之外可能还有很多,比如 .php、.asp 等等。

标签: security iis-7 web-config httphandler


【解决方案1】:

将以下内容添加到文件夹中的web.config 文件中,该文件包含您希望仅作为静态内容提供的文件:

<configuration>
    <system.webServer>
        <handlers>
           <clear />
            <add 
                name="StaticFile" 
                path="*" verb="*" 
                modules="StaticFileModule,DefaultDocumentModule,DirectoryListingModule" 
                resourceType="Either" 
                requireAccess="Read" />
        </handlers>
        <staticContent>
            <mimeMap fileExtension=".*" mimeType="application/octet-stream" />
        </staticContent>
    </system.webServer>
</configuration>

【讨论】:

  • 在 IIS 和 IIS Express 上测试正常,但它不适用于 VS 集成 Web 服务器。
  • @deerchao - 不会因为集成的“cassini”服务器不支持&lt;system.webServer&gt;
  • 在有人将新的 web.config 上传到您打开的上传文件夹并重新定义所有处理程序之前,它一直有效。见我的answer here。有关利用示例,请参阅 this link
  • 由于权限不足,我收到了 403.3。在&lt;handlers&gt; 标记中,我添加了&lt;remove name="StaticFile" /&gt; 而不是&lt;clear /&gt;,并将requireAccess 属性值从Write 更改为Read
  • @WouterVanherck 很高兴您发现我的回答很有帮助:)
猜你喜欢
  • 1970-01-01
  • 2020-06-18
  • 1970-01-01
  • 2011-06-14
  • 1970-01-01
  • 1970-01-01
  • 2018-01-22
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多