What is best way to reference directory from different locations?

  • Thread starter Thread starter Kent P. Iler
  • Start date Start date
K

Kent P. Iler

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
 
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">
 
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
 
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
 
For client paths I normally don't make a property like that, but just do the
following:
<%=Request.ApplicationPath%>
 
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
 
Back
Top