After messing around with RouteValueDictionary, RouteData, RequestContext and all sorts of Route classes, I was almost ready to give up and hardcode my way in. I started this project a while ago so i had forgotten about the customizations to the WebFormViewEngine class i had done. I m gonna go ahead and post my solution, even though i realize it may not be the most elegant, secure or practical (in terms of best practices).
First of all i had extendend the WebFormViewEngine class and overridden the FindView method:
public class CustomViewEngine : WebFormViewEngine
{
public override ViewEngineResult FindView(ControllerContext controllerContext, string viewName, string masterName, bool useCache)
{
ViewEngineResult result = null;
var request = controllerContext.HttpContext.Request;
// modify stuff here
result = base.FindView(controllerContext, viewName, masterName, useCache);
return result;
}
}
What i did was add a static property to my utility class, like so:
public static string CurrentViewPath { get; set; }
and modified the FindView method to capture the ViewEngineResult and get the ViewPath:
public override ViewEngineResult FindView(ControllerContext controllerContext, string viewName, string masterName, bool useCache)
{
ViewEngineResult result = null;
var request = controllerContext.HttpContext.Request;
// modify stuff here
result = base.FindView(controllerContext, viewName, masterName, useCache);
System.Web.Mvc.WebFormView wfvView = (System.Web.Mvc.WebFormView)result.View;
HelperFunctions.CurrentViewPath = wfvView.ViewPath.Replace(viewName + ".aspx","");
return result;
}
this gave me the virtual path to the view, which is just what i needed. the only thing left to do was go back to the utility class and use the HttpContext.Current.Request.MapPath method to get the full physical path of where the current view file is:
string ViewPath = HttpContext.Current.Request.MapPath(CurrentViewPath);
And bingo!
It is sort of a roundabout hackish way to do this, bu hey, if it works...
Thanks for the help and useful suggestions everyone.