02 August 2005

How to get the ApplicationPath in ASP.Net?

If you have a virtual directory:
string path = HttpContext.Current.Request.ApplicationPath;

If your site is on the root or a virtual directory:

string path = HttpContext.Current.Request.ApplicationPath;
if (path == "/")
path = "http://" + Request.Url.Host;
else
path += "/";

No comments: