IHTTPHandler on the Api website

I am trying to use an existing IHttpHandlerwebsite ASP.NET MVC\WEB APIdeployed on VS IIS EXPRESS 8.0and in productionIIS 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 for URLs ending in .mp4

I registered MP4DownloadHandlerinweb.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 receive request with a url:

localhost:6032/get/GetImage/test.mp4

I get the following answer:

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 debugging, I see that mine was ProcessRequestnot called, so I can conclude that this is not the case when the handler does not find the file.

Is there anything special to make IHttpHadlers work with MVC?

+4

Source: https://habr.com/ru/post/1570271/


All Articles