0

I've got an image handler on my site which works on the url below. Obviously with being an asp.net httphandler it has the .ashx extension, even though it returns content with mime type image/jpeg

https://xxxxx/image.ashx?id=78164&imagelibraryid=0404fd0c-e681-4a5c-9899-f2709aaf7e0c

We want to use cloudflare for caching and serving images, but for it to work properly you have to use image urls with standard extensions i.e. jpg/gif/png etc.

Is there anyway my httphandler can detect and process any requests to image.jpeg?

Only image.jpeg should be handled by the httphandler, any other XXX.jpeg would still need to be served from the filesystem.

Is it possible?

Thanks

Ben Durkin
  • 429
  • 1
  • 6
  • 20

1 Answers1

0

I think you have three options to allow you to serve the same images with a new url that looks like:

https://xxxxx/something-custom/images/78164/0404fd0c-e681-4a5c-9899-f2709aaf7e0c.jpg

Option one - use IIS rewrite rules to serve publically on one url that has proper extensions and rewrite the address inside the webserver so that the fragments get passed into the ashx handler.

Option two - use aspnet routing, originally designed for MVC, with a bunch of plumbing code to pass the data between the two paradigms, as detailed in this SO question

Option three - rewrite the code by moving it out of ashx into a new api controller as ashx handlers are a bit dated these days and mvc and model binding are often easier and more testable. Most of the core logic can probably be done quickly with lift and shift, and just use routing and mvc to map the new url fragments into variables consumed by your business logic.

alastairtree
  • 3,960
  • 32
  • 49