Offer an MVC ActionResult as an alternative to using the HttpModule.
ASP.NET MVC is intrinsically limited (by bad design), and cannot achieve the same performance as an HttpModule can, because it cannot pass a request completely back to IIS for handling.
In addition, an ActionResult cannot control which routes are directed to it, which means the CloudFront, Image404, ImageHandlerSyntax, and ImageFolderSyntax plugins cannot be supported from the ActionResult.
This limitation also means that the developer will be responsible for creating routes for every syntax he wishes to use, every plugin he wishes to use, and every file extension (or lack thereof) he wishes to support. Plugins which will probably need separat routes: Diagnostics, RemoteReader, SqlReader, AzureReader, MongoReader, and Gradient.
And since an ActionResult cannot 'escape' handling a request, even serving static, unmodified images will have to be routed through managed code, adding additional overhead.
The ImageResizer offers .RewriteDefaults, .Rewrite, .PostRewrite, and .AuthorizeImage events that are far more capable and flexible than ASP.NET routes, and offer better performance.
However, it seems that many users are determined to 'take advantage' of MVC, and I've gotten many e-mails from users making their own ActionResult classes that are even worse than they could be, lacking even integration with the disk caching system, proper memory management, or correct caching and content-type headers.
So, it seems that the only thing to do for these folks is provide a proper (yet intrinsically hopeless) implementation so they won't shoot themselves in the foot.
Martin Kirk commented
Whats the status of this ?
Is there any examples of how to use ActionResult and still get the benefits of ImageResizing ??
In my case, i want to store the images in a folder, not acceccible by URL, I want them to be located on a Network drive and then let MVC load them dynamically.
@Sam Have you looked at the Pipeline.AuthorizeImage event? What about the HttpModule approach seems difficult?
It's true, I do need to vastly improve the documentation, but I'm even more concerned if you've found limitations with the HttpModule.
Sam Stephens commented
The thing is that there are situations where image requests need to hook into the infrastructure of a website. For example usage for a project I've been involved in requires the images being resized to be secured based on user roles and metadata associated with the image record. For this project, it makes sense to route these requests via an MVC controller so the authorisation approach and code is standardised across both views and images.
So, whilst usage of ActionResult may indicate naivety, there are legitimate reasons to deal with image requests via MVC controllers.
Honestly I think that if you wish to discourage use of ActionResult, you need to make the HttpModule approach easier, rather than make ActionResult harder to use and disadvantage those of us who have legitimate reasons for using it.
I'm really bad at making things hard to do... What do you suggest? Make an obnoxious constructor argument? Mark it depreciated from the get-go? I could really use some ideas here...
Dan Friedman commented
Just make it hard to do. Many people understand Actions, not many understand HttpModules. They will usually do what they understand, even if it isn't right.