First time here? Check out the site's "greatest hits" or read a post from the archives. Feel free to leave a comment or ask a question, and consider subscribing to the latest posts via RSS or e-mail. Thanks for visiting!
« My Christmas (or Birthday List) | Main | My Ultimate TabletPC »

I need a function from ASP.NET that gives me, reliably and guaranteed, without a config file, the base virtual directory of the current website.  So if I'm in c:\inetpub\wwwroot\web (ne http://localhost/web) then I want “/web/.” 

But (here's the fart part) I can't seem to find a way that gives it to me INDEPENDANT of the current Context's path.  Meaning, if the VERY FIRST (app start) page hit on the site is http://localhost/web/balances/balances.aspx then I still need “/web/“ not “/web/balances/.“

This is the closest I've got:

return HttpRuntime.AppDomainAppVirtualPath + "/";

However, this appears to occasionally (read: flaky) return a different path like /web/images/ or /web/someotherpagedirectory. 

What am I missing?



Tuesday, November 18, 2003 4:59:04 PM (Pacific Standard Time, UTC-08:00)
So you need the highest level directory of a web request? Or do you need the base directory of a web application?

For the former, you can do something with the Request.ServerVariables["PATH_INFO"] value, like splitting it on '/' and grabbind the first element.

The latter is easier, and you can use Page.ResolveUrl("~/").
Tuesday, November 18, 2003 5:15:27 PM (Pacific Standard Time, UTC-08:00)
The base dir of the web app can also be gotten from Request.ApplicationPath. Though as Kurt points out, that isn't necessarily the left-most directory in the URL.
Wednesday, November 19, 2003 8:26:23 PM (Pacific Standard Time, UTC-08:00)
How about HttpRequest's ApplicationPath property?
Friday, November 21, 2003 2:57:12 PM (Pacific Standard Time, UTC-08:00)
I use

System.AppDomain.CurrentDomain.BaseDirectory

Because you don't have to add a ref to System.Web from other libraries.. I usually do, but using this lets you get away with not having to. No reliance on an HttpRequest object
Sean
Comments are closed.

Contact

Sponsors

Hosting By

On this page...

Tags

Calendar

<December 2008>
SunMonTueWedThuFriSat
30123456
78910111213
14151617181920
21222324252627
28293031123
45678910

Archives

Google Ads