【问题标题】:IIS - Using HttpHandler for all files except for oneIIS - 对除一个以外的所有文件使用 HttpHandler
【发布时间】:2012-03-19 03:19:01
【问题描述】:

我在 .NET 中为所有 *.html 文件使用自定义 HttpHandler,但是我想为文件 foo.html 创建一个例外,它应该作为硬盘驱动器上的静态文件处理。我试过了:

  <httpHandlers>
     <remove verb="*" path="*.html" />
     <add verb="*" path="/foo.html" type="System.Web.StaticFileHandler" />
     <add verb="*" path="*.html" validate="false" type="Imp.Handler" />
  </httpHandlers>

还有:

  <httpHandlers>
     <remove verb="*" path="*.html" />
     <add verb="*" path="*.html" validate="false" type="Imp.Handler" />
     <add verb="*" path="/foo.html" type="System.Web.StaticFileHandler" />
  </httpHandlers>

但是,两者都会导致 Imp.Handler 仍然处理 foo.html 请求。我做错了什么?

IIS 正在经典模式下运行。

【问题讨论】:

    标签: asp.net iis iis-7 web-config


    【解决方案1】:

    可能这个方法可以帮助你,将文件移动到另一个文件夹并禁用这个文件夹的httphandler。

    <location allowOverride="false" path="Static">
        <system.web>
          <httpHandlers>
            <remove verb="*" path="*.htm"/>
            <!--<add verb="*" path="/foo.htm" type="System.Web.StaticFileHandler" />-->
          </httpHandlers>
        </system.web>
    </location>
    
    <httpHandlers>
         <add verb="*" path="*.html" validate="false" type="Imp.Handler" />
    </httpHandlers>
    

    我试着测试一下,问题是:

    if i remove HttpHandler for the "*.html" in the location element,and add a other httphandler will doesn't worked.例如:

    <location>
        <remove verb="*" path="*.htm"/>
        <add verb="*" path="foo.html" validate="false" type="Imp.Handler" />
    </location>
    

    【讨论】:

    • 不,我需要路径为/foo.html
    • 好的,或者你可以使用IIS的ISAPI来解决这个问题。Ionics Isapi Rewrite Filter
    猜你喜欢
    • 1970-01-01
    • 2010-10-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-14
    • 1970-01-01
    相关资源
    最近更新 更多