sharing master page question

Discussion in 'ASP .Net' started by Cirene, May 16, 2008.

  1. Cirene

    Cirene Guest

    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!
    Cirene, May 16, 2008
    #1
    1. Advertising

  2. 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.
    --
    Nathan Sokalski

    http://www.nathansokalski.com/

    "Cirene" <> wrote in message
    news:...
    >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!
    >
    Nathan Sokalski, May 16, 2008
    #2
    1. Advertising

  3. Cirene

    Cirene Guest

    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!

    "Nathan Sokalski" <> wrote in message
    news:...
    > 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.
    > --
    > Nathan Sokalski
    >
    > http://www.nathansokalski.com/
    >
    > "Cirene" <> wrote in message
    > news:...
    >>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!
    >>

    >
    >
    Cirene, May 16, 2008
    #3
  4. 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)
    --
    Nathan Sokalski

    http://www.nathansokalski.com/

    "Cirene" <> wrote in message
    news:...
    > 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!
    >
    > "Nathan Sokalski" <> wrote in message
    > news:...
    >> 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.
    >> --
    >> Nathan Sokalski
    >>
    >> http://www.nathansokalski.com/
    >>
    >> "Cirene" <> wrote in message
    >> news:...
    >>>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!
    >>>

    >>
    >>

    >
    >
    Nathan Sokalski, May 17, 2008
    #4
  5. Cirene

    clintonG Guest

    The root path operator will function with anything marked runat="server"

    "Nathan Sokalski" <> wrote in message
    news:%...
    > 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)
    > --
    > Nathan Sokalski
    >
    > http://www.nathansokalski.com/
    >
    > "Cirene" <> wrote in message
    > news:...
    >> 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!
    >>
    >> "Nathan Sokalski" <> wrote in message
    >> news:...
    >>> 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.
    >>> --
    >>> Nathan Sokalski
    >>>
    >>> http://www.nathansokalski.com/
    >>>
    >>> "Cirene" <> wrote in message
    >>> news:...
    >>>>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!
    >>>>
    >>>
    >>>

    >>
    >>

    >
    >
    clintonG, May 17, 2008
    #5
  6. 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


    "Nathan Sokalski" <> wrote in message
    news:#...
    > 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)
    > --
    > Nathan Sokalski
    >
    > http://www.nathansokalski.com/
    >
    > "Cirene" <> wrote in message
    > news:...
    >> 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!
    >>
    >> "Nathan Sokalski" <> wrote in message
    >> news:...
    >>> 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.
    >>> --
    >>> Nathan Sokalski
    >>>
    >>> http://www.nathansokalski.com/
    >>>
    >>> "Cirene" <> wrote in message
    >>> news:...
    >>>>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!
    >>>>
    >>>
    >>>

    >>
    >>

    >
    >
    Jeremy Shovan, May 17, 2008
    #6
  7. Cirene

    Cirene Guest

    I tried both and they didn't work in both browsers. Maybe my PC is
    possessed! :-x

    "clintonG" <> wrote in message
    news:...
    > The root path operator will function with anything marked runat="server"
    >
    > "Nathan Sokalski" <> wrote in message
    > news:%...
    >> 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)
    >> --
    >> Nathan Sokalski
    >>
    >> http://www.nathansokalski.com/
    >>
    >> "Cirene" <> wrote in message
    >> news:...
    >>> 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!
    >>>
    >>> "Nathan Sokalski" <> wrote in message
    >>> news:...
    >>>> 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.
    >>>> --
    >>>> Nathan Sokalski
    >>>>
    >>>> http://www.nathansokalski.com/
    >>>>
    >>>> "Cirene" <> wrote in message
    >>>> news:...
    >>>>>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!
    >>>>>
    >>>>
    >>>>
    >>>
    >>>

    >>
    >>

    >
    Cirene, May 18, 2008
    #7
  8. 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?
    --
    Nathan Sokalski

    http://www.nathansokalski.com/

    "Cirene" <> wrote in message
    news:...
    >I tried both and they didn't work in both browsers. Maybe my PC is
    >possessed! :-x
    >
    > "clintonG" <> wrote in message
    > news:...
    >> The root path operator will function with anything marked runat="server"
    >>
    >> "Nathan Sokalski" <> wrote in message
    >> news:%...
    >>> 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)
    >>> --
    >>> Nathan Sokalski
    >>>
    >>> http://www.nathansokalski.com/
    >>>
    >>> "Cirene" <> wrote in message
    >>> news:...
    >>>> 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!
    >>>>
    >>>> "Nathan Sokalski" <> wrote in message
    >>>> news:...
    >>>>> 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.
    >>>>> --
    >>>>> Nathan Sokalski
    >>>>>
    >>>>> http://www.nathansokalski.com/
    >>>>>
    >>>>> "Cirene" <> wrote in message
    >>>>> news:...
    >>>>>>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!
    >>>>>>
    >>>>>
    >>>>>
    >>>>
    >>>>
    >>>
    >>>

    >>

    >
    >
    Nathan Sokalski, May 18, 2008
    #8
  9. Cirene

    Cirene Guest

    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.
    "Nathan Sokalski" <> wrote in message
    news:...
    > 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?
    > --
    > Nathan Sokalski
    >
    > http://www.nathansokalski.com/
    >
    > "Cirene" <> wrote in message
    > news:...
    >>I tried both and they didn't work in both browsers. Maybe my PC is
    >>possessed! :-x
    >>
    >> "clintonG" <> wrote in message
    >> news:...
    >>> The root path operator will function with anything marked runat="server"
    >>>
    >>> "Nathan Sokalski" <> wrote in message
    >>> news:%...
    >>>> 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)
    >>>> --
    >>>> Nathan Sokalski
    >>>>
    >>>> http://www.nathansokalski.com/
    >>>>
    >>>> "Cirene" <> wrote in message
    >>>> news:...
    >>>>> 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!
    >>>>>
    >>>>> "Nathan Sokalski" <> wrote in message
    >>>>> news:...
    >>>>>> 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.
    >>>>>> --
    >>>>>> Nathan Sokalski
    >>>>>>
    >>>>>> http://www.nathansokalski.com/
    >>>>>>
    >>>>>> "Cirene" <> wrote in message
    >>>>>> news:...
    >>>>>>>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!
    >>>>>>>
    >>>>>>
    >>>>>>
    >>>>>
    >>>>>
    >>>>
    >>>>
    >>>

    >>
    >>

    >
    >
    Cirene, May 19, 2008
    #9
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Doug McCann
    Replies:
    1
    Views:
    993
    William Brogden
    Aug 5, 2004
  2. Zeba
    Replies:
    1
    Views:
    480
    Mark Rae
    Feb 22, 2007
  3. Andy B
    Replies:
    1
    Views:
    294
    Munna
    Jun 20, 2008
  4. Nathan Sokalski
    Replies:
    25
    Views:
    1,410
    Nathan Sokalski
    Mar 4, 2010
  5. SerpentKiss2010
    Replies:
    0
    Views:
    2,470
    SerpentKiss2010
    Apr 6, 2011
Loading...

Share This Page