Wednesday, 18 August 2010

Retrieving Actual .aspx File Path when using Url Routing

In the last few days I was almost driven to madness, trying to get in code the Path of the actual .aspx file servicing a request that was routed trough the new ASP.NET 4.0 URL Routing. The problem was that I wanted to retrieve a LocalResouce for custom control from the page resource files. After a lot of searching, I managed to find a way myself.

System.String Path = ((System.Web.Routing.PageRouteHandler)(((System.Web.Routing.Route)(HttpContext.Current.Request.RequestContext.RouteData.Route)).RouteHandler)).VirtualPath;
 
then to get the LocalResourceObject you do:
 System.String localResource = HttpContext.GetLocalResourceObject(path, LocalResourceName).ToString();

I hope this helps some of you.


Tzanimir

1 comment:

Anonymous said...

thakasino - Daftar Situs Judi Bola Online, Judi Online
Plazajudi situs judi online terpercaya Indonesia rb88 & Agen judi online terbaik, slot gacor hari ini. Minimal Deposit, ボンズ カジノ 20.000 IDR.Game dafabet link Slot Gacor: Aztec Gems, Sweet Bonanza, Waktu Deposit & Withdraw: Kurang dari 3 menit