.NETGURU
virtual directory root in asp.net controls
Messages   Related Types
This message was discovered on ASPFriends.com 'aspngreuse' list.


Noorez Khamis
Is there a way to point to a virtual directory root through html in an
asp.net control.

Here is my problem:

my Virtual directory url:

<http://localhost/myNewWebApp> http://localhost/myNewWebApp

usercontrol1.ascx looks like this:

<!--BEGIN HEADER-->
<table border="0" cellpadding="3" cellspacing="0" width="100%"
align="center">
<tr>
<td valign="top">
<img SRC="images/image1.jpg"%>" border="0">
</td>
</tr>
</table>
<hr size = "15">
<!--END HEADER-->

my directory structure

root dir
--aspxpage1.aspx
images subdir
--> image1.jpg
usercontrols subdir
--> control1.ascx
sampledir1 subdir
--> aspxpage2.aspx

I added my control to aspxpage1.aspx and aspxpage2.aspx, the image
appears correctly in aspxpage1.aspx but not aspxpage2.aspx, this is
because the path to the images directory is messed.

What is the best way to point the image to the images directory in the
virtual root
Reply to this message...
 
    
devin
I usually tell the image src to start from the root. In your case that =
would be=20

src=3D"/myNewWebapp/images/image1.jpg"

That way, no matter where in the site I move the UC, it always starts =
from the root to find the image.

HTH

Devin

----- Original Message -----
From: "Noorez Khamis" <Click here to reveal e-mail address>
To: Click here to reveal e-mail address
Sent: Wed, 15 May 2002 16:32:20 -0700
Subject: virtual directory root in asp.net controls
[Original message clipped]

Reply to this message...
 
    
Ollie Cornes

Devin's solution works for a single app, but if you rename the application
folder name or (like me) have a copy you use for testing that has a
different name, it will fail. Another approach is to add runat="server" to
the img tags and then place "~/" at the start of the src attribute, like
this:

<img runat="server" src="~/images/image1.jpg" border="0">

Be aware that this approach has a performance impact, as more server
controls are being created to build the page.

Ollie
--
http://www.RichTextBox.com
The easy way to add formatted text editing to your ASP.NET web site

----- Original Message -----
From: "devin" <Click here to reveal e-mail address>
To: "aspngreuse" <Click here to reveal e-mail address>
Sent: Thursday, May 16, 2002 3:27 AM
Subject: [aspngreuse] Re: virtual directory root in asp.net controls

I usually tell the image src to start from the root. In your case that
would be

src="/myNewWebapp/images/image1.jpg"

That way, no matter where in the site I move the UC, it always starts from
the root to find the image.

HTH

Devin

----- Original Message -----
From: "Noorez Khamis" <Click here to reveal e-mail address>
To: Click here to reveal e-mail address
Sent: Wed, 15 May 2002 16:32:20 -0700
Subject: virtual directory root in asp.net controls
[Original message clipped]

| [aspngreuse] member Click here to reveal e-mail address = YOUR ID
| http://www.aspfriends.com/aspfriends/aspngreuse.asp = JOIN/QUIT

Reply to this message...
 
    
Chris Garrett
Why not use src="../images" etc kind of thing (relative paths)? Am I being
silly?

Chris

--

Chris Garrett
http://www.chrisg.com

----- Original Message -----
From: "Ollie Cornes" <Click here to reveal e-mail address>
To: "aspngreuse" <Click here to reveal e-mail address>
Sent: Thursday, May 16, 2002 8:10 AM
Subject: [aspngreuse] Re: virtual directory root in asp.net controls

[Original message clipped]

Reply to this message...
 
    
Cameron Elliot
I though I was being smart and using <img src=3D"_images/blah.gif"> and =
having a <base href=3D"http://..."> tag in my header. This works great =
for images when you have a common header/footer control, but postbacks =
are stuffed because they too are taken from the base href tag, thus =
destroying your app.

None of this was a problem before, but I have just installed Windows xp =
and you are only allowed one web site in IIS. Thus <img =
src=3D"/_images/blah.gif"> actually maps to d:\inetpub\wwwroot NOT =
d:\inetpub\wwwroot\myapp as I need.

Also you can't use <%@ Register TagPrefix=3D"uc1" TagName=3D"Footer" =
Src=3D"/_controls/Footer.ascx" %>
as this maps to d:\inetpub\wwwroot=20

I am considering working on my application directly in =
d:\inetpub\wwwroot, and if I ever have to work on a different app, I'll =
check what I'm working on in, and swap the new app into wwwroot.

Anyone found a good solution to this yet?

-----Original Message-----
From: Chris Garrett [mailto:Click here to reveal e-mail address]
Sent: Thursday, 16 May 2002 9:19 p.m.
To: aspngreuse
Subject: [aspngreuse] Re: virtual directory root in asp.net controls

Why not use src=3D"../images" etc kind of thing (relative paths)? Am I =
being
silly?

Chris

--

Chris Garrett
http://www.chrisg.com

----- Original Message -----
From: "Ollie Cornes" <Click here to reveal e-mail address>
To: "aspngreuse" <Click here to reveal e-mail address>
Sent: Thursday, May 16, 2002 8:10 AM
Subject: [aspngreuse] Re: virtual directory root in asp.net controls

[Original message clipped]

| [aspngreuse] member Click here to reveal e-mail address =3D YOUR ID
| http://www.aspfriends.com/aspfriends/aspngreuse.asp =3D JOIN/QUIT

Reply to this message...
 
    
Noorez Khamis
The best answer that worked for me that someone already answered before
was that all you have to do is make the image a server-side control with
runat=3Dserver and then use "~/images" as the url which points to the
virtual root

Quote:

-----Original Message-----
From: Cameron Elliot [mailto:Click here to reveal e-mail address]
Sent: Thursday, May 16, 2002 3:24 PM
To: aspngreuse
Subject: [aspngreuse] Re: virtual directory root in asp.net controls

I though I was being smart and using <img src=3D"_images/blah.gif"> and
having a <base href=3D"http://..."> tag in my header. This works great
for images when you have a common header/footer control, but postbacks
are stuffed because they too are taken from the base href tag, thus
destroying your app.

None of this was a problem before, but I have just installed Windows xp
and you are only allowed one web site in IIS. Thus <img
src=3D"/_images/blah.gif"> actually maps to d:\inetpub\wwwroot NOT
d:\inetpub\wwwroot\myapp as I need.

Also you can't use <%@ Register TagPrefix=3D"uc1" TagName=3D"Footer"
Src=3D"/_controls/Footer.ascx" %>
as this maps to d:\inetpub\wwwroot=20

I am considering working on my application directly in
d:\inetpub\wwwroot, and if I ever have to work on a different app, I'll
check what I'm working on in, and swap the new app into wwwroot.

Anyone found a good solution to this yet?

-----Original Message-----
From: Chris Garrett [mailto:Click here to reveal e-mail address]
Sent: Thursday, 16 May 2002 9:19 p.m.
To: aspngreuse
Subject: [aspngreuse] Re: virtual directory root in asp.net controls

Why not use src=3D"../images" etc kind of thing (relative paths)? Am I
being
silly?

Chris

--

Chris Garrett
http://www.chrisg.com

----- Original Message -----
From: "Ollie Cornes" <Click here to reveal e-mail address>
To: "aspngreuse" <Click here to reveal e-mail address>
Sent: Thursday, May 16, 2002 8:10 AM
Subject: [aspngreuse] Re: virtual directory root in asp.net controls

[Original message clipped]

| [aspngreuse] member Click here to reveal e-mail address =3D YOUR ID
| http://www.aspfriends.com/aspfriends/aspngreuse.asp =3D JOIN/QUIT

| [aspngreuse] member Click here to reveal e-mail address =3D YOUR ID
| http://www.aspfriends.com/aspfriends/aspngreuse.asp =3D JOIN/QUIT

Reply to this message...
 
    
Cameron Elliot
Yeah I saw that, but what about <a href="/members/foo/default.aspx">? Do I have to make EVERYTHING which references a part of my web application by an absolute url a server side control? I would have thought this to be a wasteful and complex solution to a very simple requirement.

Any solution which I deploy will be in its own web application under IIS and "/" will map to the current application's root directory.

It's only because I'm developing in Windows XP that I can no longer add new web sites to IIS, and develop applications in an environment similar to that in which they will be deployed.

I wonder how Response.Redirect("/members/foo/defualt.aspx") reacts. Maybe you can specify "~members/foo/default.aspx" . Must try this.

Cameron

-----Original Message-----
From: Noorez Khamis [mailto:Click here to reveal e-mail address]
Sent: Friday, 17 May 2002 11:22 a.m.
To: aspngreuse
Subject: [aspngreuse] Re: virtual directory root in asp.net controls

The best answer that worked for me that someone already answered before
was that all you have to do is make the image a server-side control with
runat=server and then use "~/images" as the url which points to the
virtual root

Quote:

-----Original Message-----
From: Cameron Elliot [mailto:Click here to reveal e-mail address]
Sent: Thursday, May 16, 2002 3:24 PM
To: aspngreuse
Subject: [aspngreuse] Re: virtual directory root in asp.net controls

I though I was being smart and using <img src="_images/blah.gif"> and
having a <base href="http://..."> tag in my header. This works great
for images when you have a common header/footer control, but postbacks
are stuffed because they too are taken from the base href tag, thus
destroying your app.

None of this was a problem before, but I have just installed Windows xp
and you are only allowed one web site in IIS. Thus <img
src="/_images/blah.gif"> actually maps to d:\inetpub\wwwroot NOT
d:\inetpub\wwwroot\myapp as I need.

Also you can't use <%@ Register TagPrefix="uc1" TagName="Footer"
Src="/_controls/Footer.ascx" %>
as this maps to d:\inetpub\wwwroot

I am considering working on my application directly in
d:\inetpub\wwwroot, and if I ever have to work on a different app, I'll
check what I'm working on in, and swap the new app into wwwroot.

Anyone found a good solution to this yet?

-----Original Message-----
From: Chris Garrett [mailto:Click here to reveal e-mail address]
Sent: Thursday, 16 May 2002 9:19 p.m.
To: aspngreuse
Subject: [aspngreuse] Re: virtual directory root in asp.net controls

Why not use src="../images" etc kind of thing (relative paths)? Am I
being
silly?

Chris

--

Chris Garrett
http://www.chrisg.com

----- Original Message -----
From: "Ollie Cornes" <Click here to reveal e-mail address>
To: "aspngreuse" <Click here to reveal e-mail address>
Sent: Thursday, May 16, 2002 8:10 AM
Subject: [aspngreuse] Re: virtual directory root in asp.net controls

[Original message clipped]

| [aspngreuse] member Click here to reveal e-mail address = YOUR ID
| http://www.aspfriends.com/aspfriends/aspngreuse.asp = JOIN/QUIT

| [aspngreuse] member Click here to reveal e-mail address = YOUR ID
| http://www.aspfriends.com/aspfriends/aspngreuse.asp = JOIN/QUIT

| [aspngreuse] member Click here to reveal e-mail address = YOUR ID
| http://www.aspfriends.com/aspfriends/aspngreuse.asp = JOIN/QUIT
Reply to this message...
 
    
Little, Ambrose
Well, Cameron, not all of us have the luxury of developing *for* virtual
roots, so we don't have the option you have. On our intranet webfarm, we
have many applications off of one root, which (nicely) mirrors dev
configurations (because we can only have one web site).

Anyway, all that aside, the IBuySpy portal app uses
<%=Request.ApplicationPath%> whereever it needs the application root (not
the virtual root). I've used this in conjunction with the "~" (on server
control images) and have had no problemos.

--Ambrose

[Original message clipped]

******************************************************************************
The Company reserves the right to amend statements
made herein in the event of a mistake. Unless expressly
stated herein to the contrary, only agreements in writing signed
by an authorized officer of the Company may be enforced against it.
*******************************************************************************

Reply to this message...
 
 




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification