【问题标题】:Fail to execute url when using DefaultHttpHandler in IIS在 IIS 中使用 DefaultHttpHandler 时执行 url 失败
【发布时间】:2015-09-16 08:55:47
【问题描述】:

我使用 HttpHandlerFactory 创建处理程序来处理所有类型的请求(.),但是我不想处理一些静态请求类型,所以我返回 DefaultHttpHandler 。 但是在VS中,它工作正常,在IIS中,只有HtmlTemplateHandler和DoTemplateHandler工作正常,其他默认情况下的请求类型都返回“无法执行Url”异常。

        GenericHandler currentHandler = null;

        switch (extName)
        {
            case ".html":
                currentHandler = new HtmlTemplateHandler();
                break;
            case ".do":
                currentHandler = new DoTemplateHandler();
                break;
            default:
                return new DefaultHttpHandler();
        }



        return currentHandler;

以下是我的 web.config

  <system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
       <handlers>

        <add name="all" path="*.*" verb="*" modules="IsapiModule" scriptProcessor="C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" resourceType="Unspecified" preCondition="classicMode,runtimeVersionv4.0,bitness64" />
    </handlers>

【问题讨论】:

    标签: .net iis httphandler


    【解决方案1】:

    我已经解决了这个问题。

    由于 VS 和 IIS 不同,所以我们需要使用 StaticFileHander 来处理一些静态文件,例如 jpg,css,js...

    但是这个处理程序不包含在 VS 中。考虑使用反射进行创建。

                        Type type = typeof(HttpApplication).Assembly.GetType("System.Web.StaticFileHandler", true);
                    IHttpHandler handler = (IHttpHandler)Activator.CreateInstance(type, true);
                    return handler;
    

    【讨论】:

      猜你喜欢
      • 2011-08-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多