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>