Why httphandler is not working

I wrote httpHandler for an ASP.NET MVC4 site that generates an image. The function is ProcessRequestnot called. Any thoughts on why?

MVC4, IIS Express, Windows 8 Pro

Web.config> system.webServer

 <system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
    <handlers>
      <remove name="TextImage" />
      <remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
      <remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
      <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
      <add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
      <add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
      <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
      <add name="TextImage" path="textimage/*.png" verb="*" resourceType="Unspecified" type="MultiStepUI.TextImageHandler, MultiStepUI_MOBETTER" />
    </handlers>
  </system.webServer>

Using

<img src="/textimage/step1.png?q=Step 1&c=404040&w=30&h=250&z=12" />
+5
source share
2 answers

The answer can be found on the Internet if you just know what to look for.

The MVC routing mechanism tries to match all requests to the controller - this is not what we want in this case. In addition to registering the handler in Web.config, we need to tell the MVC route engine to ignore httpHandler pathso that ASP.NET can handle its routing.

I chose an example from Phil Haack

,

ASP.NET Routing , . . , , , . , , , ASP.NET .axd, .

, RouteCollection, IgnoreRoute, , StopRoutingHandler (, IRouteHandler). , , "" " , ASP.NET HTTP-. , , , .

routes.IgnoreRoute(" {}.axd/{* PathInfo} ");

.axd . , , . , HTTP , IHttpHandler. favicon.ico, . ASP.NET . , . , - :

{* }.aspx/{* pathinfo}

, URL-. . .

routes.IgnoreRoute(" {* allaspx} ", {allaspx = @". * \. aspx (/.*)? "});
routes.IgnoreRoute( "{* favicon}", {favicon = @ "(. */)? favicon.ico(/.*)?" });

? , URL- , , . , (, , ) favicon.ico( , ), .aspx. , , ASP.NET.

+12

, , . :

routes.IgnoreRoute("{*allaspx}", new {allaspx=@".*\.aspx(/.*)?"});
routes.IgnoreRoute("{*favicon}", new {favicon=@"(.*/)?favicon.ico(/.*)?"});

"*" {* allaspx} {* favicon}, . , .

0

All Articles