Root Relative Path

W

Win, Pats

I have a snippet of HTML that I inject into a number of pages throughout my
Web site at runtime. My problem is that I'm not getting the image to appear
in all documents into which this snippet is injected.

If I specify a document-relative path (e.g.,
src="../someFolder/AnotherFolder/TheGraphic.gif"), then it works fine, but
only for documents that exist at the [someFolder] level in the directory
structure.

I thought I could use a root-relative path, as follows, in order for the
image to appear on all documents throughout my site:
<img src="/someFolder/AnotherFolder/TheGraphic.gif">

But that doesn't seem to work.

How can I specify the src attribute value in order to have the image show up
correctly on all documents - regardless of the documents location in the
site's folder hierarchy?

Please note that I'm building one simple HTML string that is the same for
all pages into which it is injected - so there is no opportunity or desire
to inject a different string per document.

Thanks!
 
K

Ken Cox [Microsoft MVP]

Don't forget about the tilde (~) in ASP.NET. It resolves to the root of your
site. Therefore you can use something like

"~/images/myimage.gif"

from anywhere.

Ken
 
W

Win, Pats

Unfortunately the tilde reference to the root doesn't help in my situation
because ASP.NET isn't resolving the path. What I'm doing is simply injecting
a string of HTML into the pages via a Literal control - so it's the browser
that needs to know where the root is...

I thought that starting a path with a '/' causes a path to be
"root-relative" according to HTML fundamentals (as used in the following
<img> tag):
<img src="/someFolder/AnotherFolder/TheGraphic.gif">

Am I incorrect about that?






Ken Cox said:
Don't forget about the tilde (~) in ASP.NET. It resolves to the root of
your site. Therefore you can use something like

"~/images/myimage.gif"

from anywhere.

Ken

Win said:
I have a snippet of HTML that I inject into a number of pages throughout
my Web site at runtime. My problem is that I'm not getting the image to
appear in all documents into which this snippet is injected.

If I specify a document-relative path (e.g.,
src="../someFolder/AnotherFolder/TheGraphic.gif"), then it works fine,
but only for documents that exist at the [someFolder] level in the
directory structure.

I thought I could use a root-relative path, as follows, in order for the
image to appear on all documents throughout my site:
<img src="/someFolder/AnotherFolder/TheGraphic.gif">

But that doesn't seem to work.

How can I specify the src attribute value in order to have the image show
up correctly on all documents - regardless of the documents location in
the site's folder hierarchy?

Please note that I'm building one simple HTML string that is the same for
all pages into which it is injected - so there is no opportunity or
desire to inject a different string per document.

Thanks!
 
J

Juan T. Llibre

re:
I thought that starting a path with a '/' causes a path to be
"root-relative" according to HTML fundamentals

Sure, depending on where the "root" is configured.

Your "root directory" is always going to be wwwroot, if you
haven't configured a downlevel directory as an application.

In that case, "/someFolder/AnotherFolder/TheGraphic.gif"
refers to wwwroot/someFolder/AnotherFolder/TheGraphic.gif.

If you *have* configured an application at /someotherFolder,
then *that* relative root is /someotherFolder, and a link like
"/someFolder/AnotherFolder/TheGraphic.gif" at *that* location
will refer to
wwwroot/someotherFolder/someFolder/AnotherFolder/TheGraphic.gif

Bottom line is, you can't have the same images directory
for different applications, because the root directory will
vary for each application.






Win said:
Unfortunately the tilde reference to the root doesn't help in my situation
because ASP.NET isn't resolving the path. What I'm doing is simply
injecting a string of HTML into the pages via a Literal control - so it's
the browser that needs to know where the root is...

I thought that starting a path with a '/' causes a path to be
"root-relative" according to HTML fundamentals (as used in the following
<img> tag):
<img src="/someFolder/AnotherFolder/TheGraphic.gif">

Am I incorrect about that?






Ken Cox said:
Don't forget about the tilde (~) in ASP.NET. It resolves to the root of
your site. Therefore you can use something like

"~/images/myimage.gif"

from anywhere.

Ken

Win said:
I have a snippet of HTML that I inject into a number of pages throughout
my Web site at runtime. My problem is that I'm not getting the image to
appear in all documents into which this snippet is injected.

If I specify a document-relative path (e.g.,
src="../someFolder/AnotherFolder/TheGraphic.gif"), then it works fine,
but only for documents that exist at the [someFolder] level in the
directory structure.

I thought I could use a root-relative path, as follows, in order for the
image to appear on all documents throughout my site:
<img src="/someFolder/AnotherFolder/TheGraphic.gif">

But that doesn't seem to work.

How can I specify the src attribute value in order to have the image
show up correctly on all documents - regardless of the documents
location in the site's folder hierarchy?

Please note that I'm building one simple HTML string that is the same
for all pages into which it is injected - so there is no opportunity or
desire to inject a different string per document.

Thanks!
 
W

Win, Pats

Thank you so much for the great explanation. The clarafication of "what
specifically is the site root" is was what I was missing.





Juan T. Llibre said:
re:
I thought that starting a path with a '/' causes a path to be
"root-relative" according to HTML fundamentals

Sure, depending on where the "root" is configured.

Your "root directory" is always going to be wwwroot, if you
haven't configured a downlevel directory as an application.

In that case, "/someFolder/AnotherFolder/TheGraphic.gif"
refers to wwwroot/someFolder/AnotherFolder/TheGraphic.gif.

If you *have* configured an application at /someotherFolder,
then *that* relative root is /someotherFolder, and a link like
"/someFolder/AnotherFolder/TheGraphic.gif" at *that* location
will refer to
wwwroot/someotherFolder/someFolder/AnotherFolder/TheGraphic.gif

Bottom line is, you can't have the same images directory
for different applications, because the root directory will
vary for each application.






Win said:
Unfortunately the tilde reference to the root doesn't help in my
situation because ASP.NET isn't resolving the path. What I'm doing is
simply injecting a string of HTML into the pages via a Literal control -
so it's the browser that needs to know where the root is...

I thought that starting a path with a '/' causes a path to be
"root-relative" according to HTML fundamentals (as used in the following
<img> tag):
<img src="/someFolder/AnotherFolder/TheGraphic.gif">

Am I incorrect about that?






Ken Cox said:
Don't forget about the tilde (~) in ASP.NET. It resolves to the root of
your site. Therefore you can use something like

"~/images/myimage.gif"

from anywhere.

Ken

I have a snippet of HTML that I inject into a number of pages throughout
my Web site at runtime. My problem is that I'm not getting the image to
appear in all documents into which this snippet is injected.

If I specify a document-relative path (e.g.,
src="../someFolder/AnotherFolder/TheGraphic.gif"), then it works fine,
but only for documents that exist at the [someFolder] level in the
directory structure.

I thought I could use a root-relative path, as follows, in order for
the image to appear on all documents throughout my site:
<img src="/someFolder/AnotherFolder/TheGraphic.gif">

But that doesn't seem to work.

How can I specify the src attribute value in order to have the image
show up correctly on all documents - regardless of the documents
location in the site's folder hierarchy?

Please note that I'm building one simple HTML string that is the same
for all pages into which it is injected - so there is no opportunity or
desire to inject a different string per document.

Thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,533
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top