Я пытаюсь использовать существующий IHttpHandler
на веб-сайте ASP.NET MVC\WEB API
, развернутый на 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);
...
}
...
}
Я хочу, чтобы он обрабатывал запросы к URL-адресам, заканчивающимся на .mp4
Я зарегистрировал MP4DownloadHandler
в 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>
а также добавлены правила игнорирования в таблицу маршрутизации для механизмов маршрутизации MVC и WEB API.
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" }
);
Когда я пытаюсь сделать запрос на получение с URL-адресом:
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>
В отладке вижу, что мой ProcessRequest
не вызывался, поэтому могу сделать вывод, что дело не в том, что обработчик не находит файл.
Нужно ли сделать что-то особенное, чтобы заставить IHttpHadlers работать с MVC?
IHttpHandlers
, внедривIRouteHandler
и зарегистрировав его. stackoverflow.com/questions/13593114/ - person Brett Caswell   schedule 20.11.2016