views:

21

answers:

1

I have an ASP.NET MVC 2 project where I built a custom ImageRouteHandler, following this blog: http://www.phpvs.net/2009/08/06/aspnet-mvc-how-to-route-to-images-or-other-file-types/

It all works great when I test it locally, but after I deploy it to a subdirectory of the root folder on my webserver... all the images are still referenced by: www.blabla.com/Images instead of using the subdirectory of the project.

How can I correct this? I'm guessing I have to add something like ApplicationPath before the Images/{filename} in my Global.asax.cs: routes.Add("ImagesRoute", new Route("Images/{filename}", new ImageRouteHandler()));

I just can't seem to figure out how. Any help would be greatly appreciated!

A: 

I have resolved the issue by writing a custom ImageHelper class:

public static string ImgUrl(string applicationPath, string filename) { if (applicationPath == "/") { return "/Images/" + filename; } else { return applicationPath + "/Images/" + filename; } }

And access images in my views like so:

<%= ImageHelper.ImgUrl(Request.ApplicationPath, "test.png") %>

Erwin1441