Getting the absolute path in ASP.NET
ASP.NET
Thread Starter: Paschal
Started:
Replies: 0

Ireland .NET Developer Alliance :: Forums » Technologies » ASP.NET » Getting the absolute path in ASP.NET
« Previous Thread Next Thread »
   30 Oct 2004, 4:50
Paschal is online. Last active: 23/01/2005 01:57:13 Paschal
Getting the absolute path in ASP.NET
Typically when we create ASP.NET applications, we are developing against a virtual directory.  However, when we deploy our app to a production web server, it is likely set up as a web site.  This can have an impact on href assignments when using absolute paths.  In order for paths to be consistant between virtual directories and web sites, I created a helper method that will work in either environment.  Here is the code:

 

1: public static string GetPathFromRoot(string pathWithoutRoot)

2: {

3: string _ApplicationPath =

4: HttpContext.Current.Request.ApplicationPath;

5:

6: System.Text.StringBuilder _PathToReturn =

7: new System.Text.StringBuilder(_ApplicationPath);

8:

9: if (!pathWithoutRoot.StartsWith("/") && !_ApplicationPath.EndsWith("/"))

10: {

11: _PathToReturn.Append("/");

12: }

13:

14: _PathToReturn.Append(pathWithoutRoot);

15:

16: return _PathToReturn.ToString();

17:

18: }// GetPathFromRoot

 

 

I place this method in my global.asax.cs file.


  
  Page 1 of 1 (1 items)
Ireland .NET Developer Alliance :: Forums » Technologies » ASP.NET » Getting the absolute path in ASP.NET

Powered by Community Server :: Forums