Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 基于webapi的IHTTPHandler_C#_Asp.net Mvc_Ihttphandler - Fatal编程技术网

C# 基于webapi的IHTTPHandler

C# 基于webapi的IHTTPHandler,c#,asp.net-mvc,ihttphandler,C#,Asp.net Mvc,Ihttphandler,我尝试在ASP.NET MVC\WEB API网站上使用现有的IHttpHandler,部署在VS IIS EXPRESS 8.0和生产IIS 7.5 基本上看起来 public class MP4DownloadHandler : IHttpHandler { ... public void ProcessRequest(HttpContext context) { this.InternalRequestedFileInfo = this.GetRe

我尝试在
ASP.NET MVC\WEB API
网站上使用现有的
IHttpHandler
,部署在
VS IIS EXPRESS 8.0
和生产
IIS 7.5

基本上看起来

public class MP4DownloadHandler : IHttpHandler
{
    ...

    public void ProcessRequest(HttpContext context)
    {
        this.InternalRequestedFileInfo = this.GetRequestedFileInfo(context);
        this.InternalRequestedFileEntityTag = this.GetRequestedFileEntityTag(context);
        this.InternalRequestedFileMimeType = this.GetRequestedFileMimeType(context);

        ...
     }

     ...
 }
我希望它能够处理对以
.mp4

我在
web.config

<system.webServer>
    <handlers>
      <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
      <remove name="OPTIONSVerbHandler" />
      <remove name="TRACEVerbHandler" />

      <add name="MP4DownloadHandler" verb="*" path="*.mp4" type="MP4DownloadHandler" resourceType="Unspecified"/>


      <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />

    </handlers>
</system.webServer>
WEB API中
注册表项()

当我尝试使用url发出get请求时:

localhost:6032/get/GetImage/test.mp4
我得到以下回应:

Remote Address:127.0.0.1:8888
Request URL:http://localhost:6032/get/GetImage/test.mp4
Request Method:GET
Status Code:404 Not Found

<Error>
    <Message>
        No HTTP resource was found that matches the request URI 'http://localhost:6032/get/GetImage/test.mp4'.
    </Message>
    <MessageDetail>No route data was found for this request.</MessageDetail>
</Error>    
远程地址:127.0.0.1:8888
请求URL:http://localhost:6032/get/GetImage/test.mp4
请求方法:获取
状态代码:404未找到
未找到与请求URI名称匹配的HTTP资源http://localhost:6032/get/GetImage/test.mp4'.
找不到此请求的路由数据。
在debug中,我看到没有调用我的
ProcessRequest
,因此我可以得出结论,不是处理程序没有找到文件


要使iHttpHandler与MVC一起工作,有什么特别的事情要做吗?

您可以通过实现并注册
IRouteHandler
来配置路由以使用
iHttpHandler
localhost:6032/get/GetImage/test.mp4
Remote Address:127.0.0.1:8888
Request URL:http://localhost:6032/get/GetImage/test.mp4
Request Method:GET
Status Code:404 Not Found

<Error>
    <Message>
        No HTTP resource was found that matches the request URI 'http://localhost:6032/get/GetImage/test.mp4'.
    </Message>
    <MessageDetail>No route data was found for this request.</MessageDetail>
</Error>