What is best way to reference directory from different locations?

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
 
G

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">
 
K

Kent P. Iler

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
 
W

William F. Robertson, Jr.

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
 
R

Robert Koritnik

For client paths I normally don't make a property like that, but just do the
following:
<%=Request.ApplicationPath%>
 
K

Kent P. Iler

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
 

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,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top