sharing master page question

  • Thread starter Thread starter Cirene
  • Start date Start date
C

Cirene

I have 1 master page in the root of my website that I would like to share
with all pages, even those in my /admin and /client directories. But when
pages in the subdir's are viewed the img, css, etc... references are
incorrect because they are "root based". Any suggestion as to how to
overcome this? Or do I have to create another Master Page for the subdir
pages?

Thansk!
 
You are obviously using relative URLs in your code, which is good, but when
files in different directories are involved in the same page, it is good to
make sure they will all work for that page (and all pages they are used in).
Here are a few ideas that may help:

1. For directories that are used by almost all pages (and Master pages and
UserControls), such as an /images/ directory for example, it is good to
write it as /images/ rather than images/ so that it is relative to the root
instead of the current directory. This will save you the trouble of needing
to worry about whether to use the directory of the Page, Master Page,
UserControl, CSS file, JavaScript file, etc.

2. For any server controls, you can use ~/path/ The ~ represents the root of
the site. For more details on this, see the documentation.

Even though this may sometimes make your URLs longer than is always
absolutely necessary, it can usually save you a lot of trouble and make it
easier to modify code later in development. Hopefully some of this helps.
 
Thanks for the info.

I tried both ~/path/ and /path/ and in IE and Firefox it shows up as a emtpy
box with a x in it.

Actual html image portion was as follows...
<img alt="My Picture" src="/resources/banner.jpg" width="780"
height="124" />

Any ideas? Thanks!
 
Is there any URL you can enter directly into the address bar that is the URL
of the file (such as http://localhost:49646/resources/banner.jpg) that will
display the image? If there is, what is it? Did you double-check to make
sure the file is really where you think it is? (NOTE: The ~/path/ technique
only works with server-side controls, so it would not work with the img tag
example you included)
 
If this problem is occurring while you are debugging your site it could be
because when you run your site from the debugger on local host there is an
additional 'www' path that is added to the url..

for example the path: http://localhost:49646/resources/banner.jpg
would turn into: http://localhost:49646/www/resources/banner.jpg

So. In debug mode your path would have to be /www/path/ instead of just
/path/ but once you have your site on the server it would be just /path
without the www.

I found that a good way to work with this is to set up your local IIS to
point to the site you are currently working on.. that way you can just go to
your browser and type in http://localhost or 127.0.0.1 and you will be able
to see what your site will look like. This will help reduce your development
time too.

I know... what a pain huh?

Jeremy Shovan
 
Do you have a response to my question about whether there is a URL for the
file you can enter directly into the address bar that will display the
image?
 
I want to do everything relative if possible. If I put the image on my
website it will probably work, yes. But, i want it to be relative. Thanks.
 
Back
Top