11

我正在使用 IIS7 和应用程序请求路由扩展来充当在 Apache 上运行的 Subversion 的反向代理。

代理工作正常,我可以浏览服务器,甚至执行“签出”。但是,我无法浏览到通常被 ASP.NET 禁止的文件,例如 .cs、.csproj 等。ASP.NET 不关心的文件(例如 .txt)很好。

我尝试编辑全局 web.config 以删除这些文件的 Forbidden 处理程序映射,但似乎没有什么不同。有什么方法可以让 IIS7 中的 URL 重写模块工作,同时允许呈现所有文件扩展名?

4

4 回答 4

16

IIS7 有一个applicationHost.config文件,该文件有一个限制文件扩展名的安全部分:

<requestFiltering>
  <fileExtensions allowUnlisted="true" applyToWebDAV="true">
    <add fileExtension=".cs" allowed="false" />
    <add fileExtension=".csproj" allowed="false" />
    <add fileExtension=".vb" allowed="false" />
    <add fileExtension=".vbproj" allowed="false" />
    ....
  </fileExtensions>

更多信息:

http://learn.iis.net/page.aspx/143/how-to-use-request-filtering/

我在我的网站的 web.config 中添加了一个类似的部分,并使用一个<clear />节点来删除所有扩展。现在我可以提供 .cs、.csproj 文件和其他文件,但我还不能提供 .config 文件。

编辑:删除 hiddenSection 节点也更正了 web.config 文件的问题。这是我的本地 web.config 文件:

<system.webServer>
  <security>
    <requestFiltering>
      <fileExtensions allowUnlisted="true" applyToWebDAV="true">
        <clear />
      </fileExtensions>
      <verbs allowUnlisted="true" applyToWebDAV="true" />
      <hiddenSegments applyToWebDAV="true">
        <clear />
      </hiddenSegments>
    </requestFiltering>
  </security>
</system.webServer>
于 2009-09-27T13:34:18.473 回答
4

我让它与我的 web.config 一起工作,看起来像这样:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="ReverseProxyInboundRule1" stopProcessing="true">
                    <match url="(.*)" />
                    <conditions>
                        <add input="{CACHE_URL}" pattern="^(https?)://" />
                    </conditions>
                    <action type="Rewrite" url="{C:1}://localhost:8080/{R:1}" />
                </rule>
            </rules>
            <outboundRules>
                <rule name="ReverseProxyOutboundRule1" preCondition="ResponseIsHtml1">
                    <match filterByTags="A, Form, Img" pattern="^http(s)?://localhost:8080/(.*)" />
                    <action type="Rewrite" value="http{R:1}://svn.mysite.com/{R:2}" />
                </rule>
                <preConditions>
                    <preCondition name="ResponseIsHtml1">
                        <add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
                        <add input="{RESPONSE_CONTENT_ENCODING}" pattern="[^(gzip)]" />
                    </preCondition>
                </preConditions>
            </outboundRules>
        </rewrite>
        <security>
        <requestFiltering>
          <fileExtensions allowUnlisted="true" applyToWebDAV="true">
            <clear />
          </fileExtensions>
          <verbs allowUnlisted="true" applyToWebDAV="true" />
          <hiddenSegments applyToWebDAV="true">
            <clear />
          </hiddenSegments>
        </requestFiltering>
      </security>
    </system.webServer>
</configuration>
于 2012-11-25T05:01:19.330 回答
1

除了 Paul Stovell 的回答,我建议激活双重转义。检索文件名中包含“+”字符的文件时遇到错误。双重转义消除了这个问题:

    <configuration>
        <system.webServer>
            <rewrite>
                <rules>
                    <rule name="SVNIn" stopProcessing="false">
                        <match url="(.*)" />
                        <action type="Rewrite" url="http://localhost:8082/svn/{R:1}" />
                    </rule>
                </rules>
            </rewrite>
            <security>
                <requestFiltering allowDoubleEscaping="true">
                    <fileExtensions allowUnlisted="true" applyToWebDAV="true">
                        <clear />
                    </fileExtensions>
                    <verbs allowUnlisted="true" applyToWebDAV="true" />
                    <hiddenSegments applyToWebDAV="true">
                        <clear />
                    </hiddenSegments>
                </requestFiltering>
            </security>
        </system.webServer>
    </configuration>
于 2021-02-25T11:03:49.377 回答
0
<system.webServer>

    <security>

        <requestFiltering>

            <requestLimits maxAllowedContentLength="30000000" maxUrl="4096" maxQueryString="131072" />

        </requestFiltering>

    </security>

</system.webServer>
于 2022-01-13T12:21:46.917 回答