I have a large legacy application, and I would like to move all of our images to a CDN.
Currently, all of our images reside under the application root itself, so the paths are all like "~/Images/MyImage.jpg."
Due to the requirements of our system, I MUST determine the full URL for a given image at runtime if it is to live in the CDN. This gives us tight control on versioning, caching, etc. Making code changes image-by-image will be a very long, tedious, and error prone process.
What I would like to do is be able to hook into some mechanism in ASP.NET where I can decide how I want to resolve a tilde for an image. This would allow all our existing code to remain as-is, and images will be directed to the CDN at runtime.
I found some mentionings of VirtualPathProviders, which sounded like it might be what I was looking for, but when I tested it out, the only paths being passed into the CombineVirtualPaths function were paths that ended with .ASPX, .ASCX, and .MASTER
.
Can anyone help me find a clean, low-risk option for this?
Basically, what I need is for anywhere in my app where I have "~/images/myimage.jpg" to be rendered to the browser as "http://mycdnhost.com/myimage.jpg". This will avoid having the browser send a request to our server for the image at all.