views:

30

answers:

1

I'm using ASP.NET 4 Web forms routing, for example like this: routes.MapPageRoute("page-browse", "{Language}/{Label}", "~/Default.aspx") So the webadress could look like: http://localhost/mywebsite/eng/home

In the root of my website I have a folder "Images".

Image display works when I'm in the root of my website, e.g. by using http://localhost/mywebsite/default.aspx

But when using routing it doesn't work, because the image relative url will look at "http://localhost/mywebsite/eng/images" instead of "http://localhost/mywebsite/images"

Is there a way to prevent this using ASP.NET 4 Routing mechanism? Or is the only way to use absolute url's to images?

A: 

How are you referencing your images? You should just be able to use a virtual path to the site root, using a prefix of '/' (unless I'm completely misunderstanding the question)

e.g.

<img src="/mywebsite/images/image.jpg" />
Dave
Such a virtual path will translate to:http://www.website.com/mywebsite/images/image.jpgAnd in case the route is mywebsite/language/ it will change to:http://www.website.com/mywebsite/language/images/image.jpgYou see where the problem is? The image directory path isn't correct anymore in such a case.A solution would be to use <img src="~/mywebsite/images/image.jpg" runat="server"> but I can't use this because most images I use are manually included in the website by the user using a html editor, so runat="server" cannot be included.
Martin de Ruiter