HttpHandler的不会被调用 [英] HttpHandler not being called

查看:324
本文介绍了HttpHandler的不会被调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要编写一个HttpHandler的,这将有助于其达到嵌入资源.DLL文件在我的项目的JavaScript文件。在视图中引用不能直接看到这样的资源,所以我打算用一个HttpHandler的模块,将拦截与一个路径/ JS / [文件]任何要求,找到匹配的嵌入式文件,并返回该脚本。

I need to write a HttpHandler that will serve up JavaScript files which are embedded resources in .DLLs in my project. A reference in a view cannot directly see such a resource, so I planned to use a HttpHandler module that would intercept any request with a path /js/[file] , find a matching embedded file and return the script.

问题是,我的HttpHandler code不会被调用,尽管在web.config中的部分尝试许多不同的设置。我显然失去了一些东西,但没有错误消息,我看不出那是什么。所有我曾经得到的是从静态文件处理程序404。

The problem is that my HttpHandler code is never called, despite trying lots of different settings in the section of web.config. I'm obviously missing something but with no error messages I cannot see what that is. All I ever get is a 404 from the static file handler.

Q1)我失去了一些东西明显?

Q2)是否有办法让IIS告诉我它为什么不叫我的处理程序?

摘要:我测试的IIS防爆preSS(V8)一个ASP.NET MVC应用程序4

Summary: I am testing on IIS Express (v8) for an ASP.NET MVC 4 application.

我创建一个实现IHttpHandler的一个简单的库,并在我的测试MVC应用程序添加到该的引用,web.config中的以下行:

I created a simple library that implements IHttpHandler and added a reference to this in my test MVC application, and the following lines in web.config:

  <system.webServer>
    <validation validateIntegratedModeConfiguration="true" />
    <handlers>
      <add name="ejs" path="js/*" verb="*" type="EmbeddedJsHandler.EmbeddedJsHandler, EmbeddedJsHandler" preCondition="integratedMode" />

该库是存在的,但它永远不会被调用。与/js/test.js或其他任何要求只是导致404错误。

The library is there, but it is never called. Any request with /js/test.js or whatever just results in a 404 error.

到目前为止,我已经试过很多在处理程序code不同的配置和设置。我试过preCondition,= resourceType为未指定,模块=IsapiModulescriptProcessor ​​=%WINDIR%\\ Microsoft.NET \\框架\\ v4.0.30319 \\ ASPNET_ISAPI.DLL

So far I've tried lots of different configurations and settings in the handler code. I've tried preCondition, resourceType="Unspecified", modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll"

我试过的路径:


  js/*.js
  js/* 
  js/*.*

我检查集成模式设置部分(system.webServer)正在被使用,并确认它。

I've checked the integrated mode settings section (in system.webServer) is being used, and confirmed it is.

我搜索堆栈溢出类似案件,并尝试了许多可能的解决方案..仍然没有喜悦。

I've searched stack overflow for similar cases, and tried many of the possible solutions.. still no joy.

哎呀甚至乔恩斯基特有这些类型的问题!
为什么我的IHttpHandler被称为?

Heck even Jon Skeet has these sort of problems! Why isn't my IHttpHandler being called?

推荐答案

终于想通了意外 - 这是一个缺少routes.IgnoreRoute()在RouteConfig.cs文件 - MVC的路由引擎没有被配置为忽略这条道路,所以被它传递给静态文件处理程序。

Finally figured it out by accident - it was a missing routes.IgnoreRoute() in the RouteConfig.cs file - the MVC routing engine wasn't configured to ignore this path, so was passing it to the static file handler.

卫生署!

这篇关于HttpHandler的不会被调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆