Getting the virtual paths local to server is pretty straight forward most of the time; just use Page.ResolveURL("~/whatever"). But what if you're in the BLL part of your app? Seeing as the Page.ResolveURL is not a static method you would have to create a new instance of Page before you can reference it... not good enough.

In BLL use System.Web.HttpRuntime.AppDomainAppVirtualPath static property to get local virtual path of web application:

string url = HttpRuntime.AppDomainAppVirtualPath + "/whatever";

Note: if web application is in a server root folder AppDomainAppVirtualPath returns just "/". If web application is in a non-root folder it returns virtual path of the folder without "/" in the end.

posted on 2008-01-15 15:59  josephshi  阅读(268)  评论(0编辑  收藏  举报