Geekpedia Programming Tutorials






Get the path of the ASP.NET web application that is currently running

On Monday, June 20th 2005 at 03:49 AM
By Andrew Pociu (View Profile)
-----   (Rated 0 with 0 votes)
Advertisement
More ASP.NET Resources
You can easily retrieve the path to the running ASP.NET application, using Request.PhysicalApplicationPath:

string AppPath = Request.PhysicalApplicationPath;

If the web application is located in C:\Inetpub\wwwroot\WebApplication1, the string AppPath will contain C:\Inetpub\wwwroot\WebApplication1
Digg Digg It!     Del.icio.us Del.icio.us     Reddit Reddit     StumbleUpon StumbleIt     Newsvine Newsvine     Furl Furl     BlinkList BlinkList

Rate Rate this Knowledge Base article
Comment Current Comments
by punsisi on Wednesday, December 14th 2005 at 06:05 AM

i want to know how to get the full virtual path to a subdirectory where the ASP.NET web form running.

by PB on Friday, April 14th 2006 at 06:14 AM

Cheers its just what I have been looking for :)

by d on Thursday, June 8th 2006 at 10:45 AM

d

by Jon on Wednesday, August 16th 2006 at 08:10 PM

For Punsisi - The virtual path is Request.ApplicationPath

by matt on Tuesday, September 5th 2006 at 05:51 AM

This seems to be giving me
"C:\WINDOWS\system32"
under IIS and
"C:\Documents and Settings\myname\My Documents\Visual Studio 2005\Projects"
using the ASP development server?

by matt on Tuesday, September 5th 2006 at 05:56 AM

Actually, forget I spoke, schoolboy error!

Is there a way I can get this from within C# code?

by Josh on Saturday, September 16th 2006 at 09:44 AM

try:
System.Web.HttpContext.Current.Request.ApplicationPath

by Jeff Warner on Monday, December 10th 2007 at 02:40 PM

Server.MapPath("~") works also in C#

by Elia on Friday, September 26th 2008 at 06:01 PM

hi

do someone know how to get from
"Default2.aspx" (in current application)
to
"http://localhost/blablabla/Default2.aspx"

??

by nick on Friday, December 5th 2008 at 06:48 AM

Thank you. Is exactly what I needed. Google indexed this page right.

by mahesh on Wednesday, January 28th 2009 at 05:41 AM

i want to know how to get the full virtual path to a subdirectory where the ASP.NET web form running.

by Roopesh on Tuesday, May 12th 2009 at 06:20 AM

Thanks.. this is the code iam searching for..

by Anil Dwivedi on Saturday, July 18th 2009 at 12:13 AM

The following sample code snippet is used for get the fully qualified web application virtual path of the current website.

For example., http://servername/virtualdir.

This sample property is using "HttpContext" class to get the application path.



public string FullyQualifiedApplicationPath
{
get
{
//Return variable declaration
string appPath = null;

//Getting the current context of HTTP request
HttpContext context = HttpContext.Current;

//Checking the current context content
if (context != null)
{
//Formatting the fully qualified website url/name
appPath = string.Format("{0}://{1}{2}{3}",
context.Request.Url.Scheme,
context.Request.Url.Host,
context.Request.Url.Port == 80 ? string.Empty : ":" context.Request.Url.Port,
context.Request.ApplicationPath);
}

return appPath;
}
}

by Kieran on Tuesday, January 12th 2010 at 07:17 AM

Also look at resolveUrl

by Ali on Monday, January 25th 2010 at 07:35 AM

Thanks - was looking for this

by ankush on Thursday, February 4th 2010 at 07:25 AM

Server.MapPath("~") works also in C#

by stillatmylinux on Thursday, March 11th 2010 at 02:31 PM

System.Web.HttpContext.Current.Server.MapPath("~" )


Comment Comment on this Knowledge Base article
Name: Email:
Message:
Knowledge Base Related Knowledge Base Articles
There are no related KB articles.

Comment Related Source Code
There is no related code.

Comment Related Tutorials
There are no related tutorials.

Jobs ASP.NET Job Search
My skills include:

Enter a City:

Select a State:


Advanced Search >>
Latest Tech Bargains

Advertisement

Free Magazine Subscriptions

Today's Pictures

Today's Video

Other Resources

Latest Download

Latest Icons