I want all the urls for my images in my ASP.NET MVC application to be of the form:
www.mydomain.com/img/someimagename.png
However, I currently have all my images in my MVC project in the: /Content/img/ folder.
How can I write a route that will map /img to /Content/img?
Images don't pass through the ASP.NET stack. IIS handles those requests. You need to write an HttpModule if you want your ASP.NET application to handle image requests. This blog shows you how to do this: http://weblogs.asp.net/jgaylord/archive/2009/05/04/letting-asp-net-handle-image-file-extensions-in-iis-6.aspx
But an easier solution would be to just create a virtual directory in IIS.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With