Skip to content

Instantly share code, notes, and snippets.

@mcintyre321
Created August 6, 2015 15:50
Show Gist options
  • Save mcintyre321/ff67ffa8e2f0c8ef86da to your computer and use it in GitHub Desktop.
Save mcintyre321/ff67ffa8e2f0c8ef86da to your computer and use it in GitHub Desktop.
RazorHostFactory for debugging embedded resources
public class MyCustomRazorHostFactory : WebRazorHostFactory
{
public override System.Web.WebPages.Razor.WebPageRazorHost CreateHost(string virtualPath, string physicalPath)
{
// Implementation stolen from MvcRazorHostFactory :)
var host = base.CreateHost(virtualPath, physicalPath);
if (!host.IsSpecialPage)
{
return new MyCustomRazorHost(virtualPath, physicalPath);
}
return host;
}
}
public class MyCustomRazorHost : MvcWebPageRazorHost
{
public MyCustomRazorHost(string virtualPath, string physicalPath)
: base(virtualPath, physicalPath)
{
var vpp =
(EmbeddedResourceVirtualPathProvider.Vpp) System.Web.Hosting.HostingEnvironment.VirtualPathProvider;
var resource = vpp.GetResourceFromVirtualPath(virtualPath);
if (resource != null)
{
PhysicalPath = resource.Filename;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment