Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I route "/img/" to the "/Content/img" folder in ASP.NET MVC 3?

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?

like image 763
Ardvark Avatar asked Jul 02 '11 22:07

Ardvark


1 Answers

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.

like image 76
lahsrah Avatar answered Oct 31 '22 16:10

lahsrah