Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I resolve ASP.NET "~" app paths to the website root without a Control being present?

I want to Resolve "~/whatever" from inside non-Page contexts such as Global.asax (HttpApplication), HttpModule, HttpHandler, etc. but can only find such Resolution methods specific to Controls (and Page).

I think the app should have enough knowledge to be able to map this outside the Page context. No? Or at least it makes sense to me it should be resolvable in other circumstances, wherever the app root is known.

Update: The reason being I'm sticking "~" paths in the web.configuration files, and want to resolve them from the aforementioned non-Control scenarios.

Update 2: I'm trying to resolve them to the website root such as Control.Resolve(..) URL behaviour, not to a file system path.

like image 607
John K Avatar asked Apr 07 '10 01:04

John K


1 Answers

Here's the answer: ASP.Net: Using System.Web.UI.Control.ResolveUrl() in a shared/static function

string absoluteUrl = VirtualPathUtility.ToAbsolute("~/SomePage.aspx");
like image 130
Max Toro Avatar answered Sep 19 '22 15:09

Max Toro