473,503 Members | 1,629 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do I get the virtual root in a C# asp.net application

Hello.

I am writing an ASP.NET C# application. I have made a user control so that I
can reuse some code. However, I need to be able to determine what the
virtual root of the website is, so that I can dynamically generate the
proper links to other pages on the site. Basically, I have the following
site layout. I am developing the site in a virual directory on localhost
before it is deployed to an actual site, so I need the solution to work in
both with localhost and with an actual website.

IE: http://www.mydomain.com/otherpages/otherpage1.aspx should return
http://www.mydomain.com
http://localhost/mydomain/otherpages/otherpage1.aspx should return
http://localhost/mydomain

http://www.mydomain.com or http://localhost/mydomain
- login.aspx
- /scripts/
- jscript1.js
- jscript2.js
- /otherpages/
- otherpage1.aspx
- otherpage2.aspx
- /usercontrols/
- usercontrol1.ascx
- usercontrol2.ascx

How can I get the virtual root from within C#.

-Ryan
Nov 18 '05 #1
3 7154
"Ryan Taylor" <rt*****@stgeorgeconsulting.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
However, I need to be able to determine what the virtual root of the website is, so that I can dynamically generate the proper links to other pages on the site.


Can't you just use relative addressing? E.g.

<root>
\controls
control.ascx
\images
image.jpg

In order for control.ascx to "see" image.jpg, it doesn't need to know it's
*actual* fully-qualified filespec within \Inetpub\wwwroot. All it has to do
is refer to it relative to its own folder i.e. ../images/image.jpg
Nov 18 '05 #2
can't you just use the
~/stuff/file.ext

The ~ is the holder for the "root"
--
Curt Christianson
Owner/Lead Developer, DF-Software
Site: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com
"Ryan Taylor" <rt*****@stgeorgeconsulting.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Hello.

I am writing an ASP.NET C# application. I have made a user control so that
I
can reuse some code. However, I need to be able to determine what the
virtual root of the website is, so that I can dynamically generate the
proper links to other pages on the site. Basically, I have the following
site layout. I am developing the site in a virual directory on localhost
before it is deployed to an actual site, so I need the solution to work in
both with localhost and with an actual website.

IE: http://www.mydomain.com/otherpages/otherpage1.aspx should return
http://www.mydomain.com
http://localhost/mydomain/otherpages/otherpage1.aspx should return
http://localhost/mydomain

http://www.mydomain.com or http://localhost/mydomain
- login.aspx
- /scripts/
- jscript1.js
- jscript2.js
- /otherpages/
- otherpage1.aspx
- otherpage2.aspx
- /usercontrols/
- usercontrol1.ascx
- usercontrol2.ascx

How can I get the virtual root from within C#.

-Ryan

Nov 18 '05 #3
on aspx page you simply can use:

someproperty="<%= Request.ApplicationPath.TrimEnd('/') %>/somefolder/somefile"

"Ryan Taylor" <rt*****@stgeorgeconsulting.com> wrote in message news:<#P**************@TK2MSFTNGP12.phx.gbl>...
Hello.

I am writing an ASP.NET C# application. I have made a user control so that I
can reuse some code. However, I need to be able to determine what the
virtual root of the website is, so that I can dynamically generate the
proper links to other pages on the site. Basically, I have the following
site layout. I am developing the site in a virual directory on localhost
before it is deployed to an actual site, so I need the solution to work in
both with localhost and with an actual website.

IE: http://www.mydomain.com/otherpages/otherpage1.aspx should return
http://www.mydomain.com
http://localhost/mydomain/otherpages/otherpage1.aspx should return
http://localhost/mydomain

http://www.mydomain.com or http://localhost/mydomain
- login.aspx
- /scripts/
- jscript1.js
- jscript2.js
- /otherpages/
- otherpage1.aspx
- otherpage2.aspx
- /usercontrols/
- usercontrol1.ascx
- usercontrol2.ascx

How can I get the virtual root from within C#.

-Ryan

Nov 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
14406
by: Jacky Luk | last post by:
Hi all, If I need to make a C# application, do I need to set up a virtual dir such as inetroot on the Harddisks. How do I set up such thingy? Thanks Jack
5
3655
by: Leszek | last post by:
Hello, Could anybody explain what's a difference between a virtual directory and an application root under IIS? I'm a little bit confused. This is mu problem: Let's assume the following...
8
3364
by: nick | last post by:
I have a problem and I've been using a cheezy work around and was wondering if anyone else out there has a better solution. The problem: Let's say I have a web application appA. Locally, I set...
7
2379
by: Jaydeep | last post by:
Hi, Anybody knows how to create virtual directory programmatically under root directory ofcourse from code-behind. I am developing web-based application where I need to create a folder and making...
3
2155
by: Manso | last post by:
Hi, We have an application that is installed in default web site (root web site). The same application will be installed as virtual directories under the root site e.g. <default web site>/app1...
16
11720
by: B Letts | last post by:
Hi - I'm currently using the FileUpload control to allow people to upload files to my website. This all works fine, as long as I'm going to a physical path on my server. However, I need to...
2
2670
by: §iD` | last post by:
Hi! I would like to create a virtual folder (which I want to mount) and populate managing his content by a DLL or something like that in VB.NET (2.0). How can I acomplish this? Thanks to...
2
1110
by: cisco | last post by:
My main site is in .NET 2.0 but i have one virtual directory under this that i want to run under 1.1. When i change the mode to 1.1 and try to browse to it it seems to pull in the root's web.config...
1
1928
by: Richard Payne | last post by:
Hi I'm having a problem with cookies in a virtual directory, A cookie is created by an ASP application in the root folder i.e. http://xxx.yyy.com I'm unable to read this cookie in a virtual...
4
3312
by: tshad | last post by:
I have a site www.stf.com and a site www.stfstage.com (where I do all my testing). The problem is that www.stfstage.com is only internal and I need to get access from the outside (without...
0
7202
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7084
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7328
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6991
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5578
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5013
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4672
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3154
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1512
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.