What is best way to reference directory from different locations?

Discussion in 'ASP .Net' started by Kent P. Iler, Sep 30, 2004.

  1. Kent P. Iler

    Kent P. Iler Guest

    Hi,

    I am trying to reference images from an images directory immediately off the
    root level. The problem is that on my dev machine, the url is
    <machine>/hbmlocal/images, and on the production server, the url is
    <machine>/images

    I've tried using the "~" operator along with runat="server", and that works
    most of the time. However, I have a situation in a user control where the
    "~" isn't working. Here is the line:

    td runat="server" rowspan="4" width="100%"
    style="BACKGROUND-IMAGE:~/Images/drill_left.gif; BACKGROUND-REPEAT:
    repeat-x"

    I'm including this user control from multiple files at different directory
    levels, so I can't just use "../..", etc.

    Any suggestions?

    Thanks.

    -- Kent Iler
     
    Kent P. Iler, Sep 30, 2004
    #1
    1. Advertisements

  2. Kent P. Iler

    Guest Guest

    You might try creating a BaseURL setting in your web.config and make it a
    property of your page. Then you can reference it like

    <img src="<%=this.BaseURL%>/images/button.gif">
     
    Guest, Sep 30, 2004
    #2
    1. Advertisements

  3. Kent P. Iler

    Kent P. Iler Guest

    Is there a reason why the "~" won't work?

    I'd have to have some logic to pull the server name so that it auto-sets
    based on if it's on the dev or production server.

    Thanks for your reply!

    --Kent
     
    Kent P. Iler, Oct 1, 2004
    #3
  4. The ~ works for server side resolution of an address. It resolves to the
    root path of the application. Using the style attribute is client side.
    The browser doesn't know how to process the ~.

    I use to different version of my web.config, one for each server. It is a
    little more maintenance setting up, but once the web.configs are fairly
    static, there isn't really a problem.

    bill
     
    William F. Robertson, Jr., Oct 1, 2004
    #4
  5. For client paths I normally don't make a property like that, but just do the
    following:
    <%=Request.ApplicationPath%>
     
    Robert Koritnik, Oct 1, 2004
    #5
  6. Kent P. Iler

    Kent P. Iler Guest

    Thank you!

    I think that's the way I'll also implement this.

    --Kent
     
    Kent P. Iler, Oct 3, 2004
    #6
  7. Kent P. Iler

    Kent P. Iler Guest

    Well, I used this and it worked great in my dev environment. However,
    when I copied the project to my production server, the reference is
    completely removing the server name. For example, an image tag should
    have the reference http://localserver/project/images/pic1.jpg on my
    dev machine, and on the production server the reference should be
    http://prodserver/images/pic1.jpg. However, on production, the image
    reference is set to http://images/pic1.jpg.

    Any suggestions?

    Thanks again!

    --Kent Iler
     
    Kent P. Iler, Oct 6, 2004
    #7
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.