473,387 Members | 1,535 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Determing web-site root

Hi all

Is there anyway of locating the root folder for your current web-site, ie if
I have a site running on http://intranet/applicationname, is there anywhere
in .Net that contains that info?

I've looked at the Uri class but it doesn't seem to cover that, it will go
up to http://intranet/ but I need to know the root of the app itself, it
could be http://intranet/mainsite/subsite/applicationname for all I know.

Any ideas?
Does that make sense?
Thanks
Kev
Jun 26 '06 #1
7 1153
Hi Mantorok,

You could use the below statements to get the absoluteUrl

string url=this.Request.Url.AbsoluteUri.ToString();
string absoluteUrl = url.Substring(0, url.LastIndexOf('/'));

Regards,
-Bhuvana
[http://www.syncfusion.com/faq/aspnet/default.aspx]

Jun 26 '06 #2
You can construct it very easily with Request.Url.Host and Request.ApplicationPath.

Dim appname as string = Request.Url.Host
Dim fullappname as string = _
"The application root's full URL is : " & "http://" & appname & Request.ApplicationPath & "/"

See it working at : http://asp.net.do/test/apppath.aspx
Juan T. Llibre, asp.net MVP
aspnetfaq.com : http://www.aspnetfaq.com/
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
"Mantorok" <ma******@mantorok.com> wrote in message news:e7**********@newsfeed.th.ifl.net...
Hi all

Is there anyway of locating the root folder for your current web-site, ie if I have a site running
on http://intranet/applicationname, is there anywhere in .Net that contains that info?

I've looked at the Uri class but it doesn't seem to cover that, it will go up to http://intranet/
but I need to know the root of the app itself, it could be
http://intranet/mainsite/subsite/applicationname for all I know.

Any ideas?
Does that make sense?
Thanks
Kev

Jun 26 '06 #3
Juan T. Llibre wrote:
You can construct it very easily with Request.Url.Host and Request.ApplicationPath.

Dim appname as string = Request.Url.Host
Dim fullappname as string = _
"The application root's full URL is : " & "http://" & appname & Request.ApplicationPath & "/"

See it working at : http://asp.net.do/test/apppath.aspx
Which fails if the site is using SSL.



Juan T. Llibre, asp.net MVP
aspnetfaq.com : http://www.aspnetfaq.com/
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
"Mantorok" <ma******@mantorok.com> wrote in message news:e7**********@newsfeed.th.ifl.net...
Hi all

Is there anyway of locating the root folder for your current web-site, ie if I have a site running
on http://intranet/applicationname, is there anywhere in .Net that contains that info?

I've looked at the Uri class but it doesn't seem to cover that, it will go up to http://intranet/
but I need to know the root of the app itself, it could be
http://intranet/mainsite/subsite/applicationname for all I know.

Any ideas?
Does that make sense?
Thanks
Kev


Jun 26 '06 #4
re:
Which fails if the site is using SSL.
You can always do an if using either :

Request.ServerVariables("SERVER_PORT_SECURE")
or
System.Web.HttpRequest.IsSecureConnection

....can't you ?


Juan T. Llibre, asp.net MVP
aspnetfaq.com : http://www.aspnetfaq.com/
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
"Ray Booysen" <rj***********@rjb.za.net> wrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl... Juan T. Llibre wrote:
You can construct it very easily with Request.Url.Host and Request.ApplicationPath.

Dim appname as string = Request.Url.Host
Dim fullappname as string = _
"The application root's full URL is : " & "http://" & appname & Request.ApplicationPath & "/"

See it working at : http://asp.net.do/test/apppath.aspx


Which fails if the site is using SSL.



Juan T. Llibre, asp.net MVP
aspnetfaq.com : http://www.aspnetfaq.com/
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
"Mantorok" <ma******@mantorok.com> wrote in message news:e7**********@newsfeed.th.ifl.net...
Hi all

Is there anyway of locating the root folder for your current web-site, ie if I have a site
running on http://intranet/applicationname, is there anywhere in .Net that contains that info?

I've looked at the Uri class but it doesn't seem to cover that, it will go up to
http://intranet/ but I need to know the root of the app itself, it could be
http://intranet/mainsite/subsite/applicationname for all I know.

Any ideas?
Does that make sense?
Thanks
Kev

Jun 26 '06 #5
Juan T. Llibre wrote:
re:
Which fails if the site is using SSL.
You can always do an if using either :

Request.ServerVariables("SERVER_PORT_SECURE")
or
System.Web.HttpRequest.IsSecureConnection

...can't you ?


Yup. ;)

Juan T. Llibre, asp.net MVP
aspnetfaq.com : http://www.aspnetfaq.com/
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
"Ray Booysen" <rj***********@rjb.za.net> wrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
Juan T. Llibre wrote:
You can construct it very easily with Request.Url.Host and Request.ApplicationPath.

Dim appname as string = Request.Url.Host
Dim fullappname as string = _
"The application root's full URL is : " & "http://" & appname & Request.ApplicationPath & "/"

See it working at : http://asp.net.do/test/apppath.aspx

Which fails if the site is using SSL.


Juan T. Llibre, asp.net MVP
aspnetfaq.com : http://www.aspnetfaq.com/
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
"Mantorok" <ma******@mantorok.com> wrote in message news:e7**********@newsfeed.th.ifl.net...
Hi all

Is there anyway of locating the root folder for your current web-site, ie if I have a site
running on http://intranet/applicationname, is there anywhere in .Net that contains that info?

I've looked at the Uri class but it doesn't seem to cover that, it will go up to
http://intranet/ but I need to know the root of the app itself, it could be
http://intranet/mainsite/subsite/applicationname for all I know.

Any ideas?
Does that make sense?
Thanks
Kev


Jun 26 '06 #6
Aha, that's where I was going wrong, I was trying to access it from the Url
alone, not the Request.

Thanks very much, that's great.
Kev

"Juan T. Llibre" <no***********@nowhere.com> wrote in message
news:uX**************@TK2MSFTNGP04.phx.gbl...
You can construct it very easily with Request.Url.Host and
Request.ApplicationPath.

Dim appname as string = Request.Url.Host
Dim fullappname as string = _
"The application root's full URL is : " & "http://" & appname &
Request.ApplicationPath & "/"

See it working at : http://asp.net.do/test/apppath.aspx
Juan T. Llibre, asp.net MVP
aspnetfaq.com : http://www.aspnetfaq.com/
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
"Mantorok" <ma******@mantorok.com> wrote in message
news:e7**********@newsfeed.th.ifl.net...
Hi all

Is there anyway of locating the root folder for your current web-site, ie
if I have a site running on http://intranet/applicationname, is there
anywhere in .Net that contains that info?

I've looked at the Uri class but it doesn't seem to cover that, it will
go up to http://intranet/ but I need to know the root of the app itself,
it could be http://intranet/mainsite/subsite/applicationname for all I
know.

Any ideas?
Does that make sense?
Thanks
Kev


Jun 26 '06 #7
re:
Thanks very much, that's great.
You're quite welcome, Mantorok.

:-)

Juan T. Llibre, asp.net MVP
aspnetfaq.com : http://www.aspnetfaq.com/
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
"Mantorok" <ma******@mantorok.com> wrote in message news:e7**********@newsfeed.th.ifl.net... Aha, that's where I was going wrong, I was trying to access it from the Url alone, not the
Request.

Thanks very much, that's great.
Kev

"Juan T. Llibre" <no***********@nowhere.com> wrote in message
news:uX**************@TK2MSFTNGP04.phx.gbl...
You can construct it very easily with Request.Url.Host and Request.ApplicationPath.

Dim appname as string = Request.Url.Host
Dim fullappname as string = _
"The application root's full URL is : " & "http://" & appname & Request.ApplicationPath & "/"

See it working at : http://asp.net.do/test/apppath.aspx
Juan T. Llibre, asp.net MVP
aspnetfaq.com : http://www.aspnetfaq.com/
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
"Mantorok" <ma******@mantorok.com> wrote in message news:e7**********@newsfeed.th.ifl.net...
Hi all

Is there anyway of locating the root folder for your current web-site, ie if I have a site
running on http://intranet/applicationname, is there anywhere in .Net that contains that info?

I've looked at the Uri class but it doesn't seem to cover that, it will go up to
http://intranet/ but I need to know the root of the app itself, it could be
http://intranet/mainsite/subsite/applicationname for all I know.

Any ideas?
Does that make sense?
Thanks
Kev



Jun 26 '06 #8

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

Similar topics

0
by: Phillip J. Eby | last post by:
PEP: 333 Title: Python Web Server Gateway Interface v1.0 Version: $Revision: 1.1 $ Last-Modified: $Date: 2004/08/27 17:30:09 $ Author: Phillip J. Eby <pje at telecommunity.com> Discussions-To:...
2
by: PatrickSA | last post by:
Hi, Am new to web services, so apologies for the basic nature of the question - and apologies in advance if this is the wrong newsgroup. We're building a new web service and I'm looking around...
0
by: Stu | last post by:
Hi, Im using VB dot net and crystal 11 I have a mainReport with a parameter @Idcustomer and in the mainReport I have a subreport @customerId They are linked using crystal. I would like to...
7
by: Jonas | last post by:
Hi. I'm trying to develop a web custom control that uses a programmatically created treeview. My problem is that I get an exception when I try to render the control. With properties do I have to...
2
by: Jeff | last post by:
Hey asp.net 2.0 My asp.net 2.0 project has got a assembly load problem: Some of my web.config settings: <membership defaultProvider="AH_MembershipProvider" userIsOnlineTimeWindow="15">
20
by: =?Utf-8?B?cmtibmFpcg==?= | last post by:
I was executing the steps given in http://suppor.microsoft.com/kb/308359 for testing a sample web service application. However, the following line gives a compilation error: localhost.Service1...
3
by: Sylvie | last post by:
My Windows Application has two forms, one form contains a grid (lets say Stock Listing), and the other is a form of one stock, contains some edit boxes for one stock's fields.. Is it possible to...
3
Paks
by: Paks | last post by:
Hi there, developing a web application and got a total mind block. I'm using the frameworks hibernate, struts and spring. And when you click on a link to a JSP-page, I want to redirect depending...
5
by: Oriane | last post by:
Hi, I have a .Net Visual Studio solution with one asp.net Web application, which uses a Asp.Net Web service. Both are compiled in debug mode, and both are using the Studio development web server...
2
by: =?Utf-8?B?YW5vbg==?= | last post by:
I am not sure if this is the right forum. Environment : Windows server 2008, IIS 7.0 I get the 'Could not load the file or assembly 'blowery.web.httpCompress' or one of its dependencies. The...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...

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.