Search code examples
htmlrelative-pathinformation-hiding

I need to reference an image in my code, from two different pages (with different paths to /images)


So, I have a function:

public string genSomeHtml(){
   //Gen some html including and image called foobar.gif
}

Now, I want to call genSomeHtml() from two different pages, but they have different paths to /images. So, I can't exactly use "../../images/foobar.gif" and I'd rather not pass a param to tell me where to look. Afterall, the calling page shouldn't care about how the html is rendered, it just needs to work.

any ideas?


Solution

  • General answer: Output your image with an absolute uri, instead of relative. so <img src="images/myphoto.jpg"> becomes <img src="http://localhost/images/myphoto.jpg">

    If that wasn't the right answer, please rephrase your question and add examples.