0

Assuming we have MVC application and image located at: /Images/image1.png

and we have action that matches this specific route

[Route("Content/{filename}")]
public ActionResult GetImage(string filename)
{
   // Process image (add watermark etc..)
}

The goal is to process the png file before it is sent to the browser.

The problem arise when we try to access this action:

/Content/image1.png

it returns 404 because .png extension is handled as static content so it thinks I'm trying to load image from that location. On the other hand if we add a slash: /Content/image1.png/ after filename it does work fine

Question is how can we make the iis to ignore png and handle it as a route instead of static content

I tried this in web.config without luck:

<system.webServer>
    <staticContent>
      <remove fileExtension=".png" />

    </staticContent>
  </system.webServer>
jekcom
  • 2,065
  • 2
  • 24
  • 34

1 Answers1

0

Ok. Found the solution. You need to add

<handlers>
  <add name="PngFileHandler" path="*.png" verb="GET" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>

Found here

jekcom
  • 2,065
  • 2
  • 24
  • 34