I try to use an existing IHttpHandler
on an ASP.NET MVC\WEB API
website, deployed on a VS IIS EXPRESS 8.0
and on a production IIS 7.5
It basically looks like
public class MP4DownloadHandler : IHttpHandler
{
...
public void ProcessRequest(HttpContext context)
{
this.InternalRequestedFileInfo = this.GetRequestedFileInfo(context);
this.InternalRequestedFileEntityTag = this.GetRequestedFileEntityTag(context);
this.InternalRequestedFileMimeType = this.GetRequestedFileMimeType(context);
...
}
...
}
I want it to handle requests to urls ending with .mp4
I registered the MP4DownloadHandler
in 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>
and also added ignore rules to the routing table for MVC and WEB API routing engines
in MVC
Register()
:
routes.IgnoreRoute(
"get/GetImage/{fileName}",
new { fileName = @".*\.mp4" }
);
in WEB API
RegisterRoutes()
config.Routes.IgnoreRoute(
routeName: "Ignoremp4WebApi",
routeTemplate: "get/GetImage/{fileName}",
constraints: new { fileName=@".*\.mp4" }
);
When I try to make a get request with a url:
localhost:6032/get/GetImage/test.mp4
I get the following response:
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>
In debug I see that my ProcessRequest
was not called, so I can conclude that it's not the case that the handler doesn't find the file.
Is there anything special to be done in order to make IHttpHadlers work with MVC?