Html helper does not use custom VirtualPathProvider

Viewed 280

I have set up a VirtualPathProvider and it is working fine for direct url calls like http://.../home/index in the address bar.

public class HomeController
{   
    public ActionResult Index()
    {
        // This triggers MyVirtualPathProvider functionallity when called via
        // the browsers address bar or anchor tag click for that matter.
        // But it does not trigger MyVirtualPathProvider for 'in-view' calls like
        // @{ Html.RenderAction("index", "home"); }
        return View();
    }
}

public class MyVirtualPathProvider : VirtualPathProvider
{

    public override System.Web.Hosting.VirtualFile GetFile(string virtualPath)
    {
        // This method gets hit after the Controller call for return View(...);
        if (MyCondition)
            return MyVirtualFileHandler.Get(virtualPath);
        return base.GetFile(virtualPath);
    }

    public override bool FileExists(string virtualPath)
    {
        // This method gets hit after the Controller call for return View(...);
        if (MyCondition)
            return true;
        return base.FileExists(virtualPath);
    }

}

However, I would like this to work for the Html helper too, but right now it is ignoring the VirtualPathProvider for the html helper calls in the view:

@{
     Html.RenderAction("index", "home");
}

Is there a way to solve this problem?

In addtion I have an override for the WebViewPage so I would be able to override the initialization for helpers, but I haven't got a clue with what or how.

Edit:

I have tried this at two computers and, oddly enough, it works on another computer. So the question would actually become:

Why does the VirtualPathProvider works on one and fails for 50% on another computer? But then this question would then become somewhat to vague, speculative even. Nonetheless I am not happy with this but it seems I would have to reinstall some things. :(

1 Answers
Related