Created
August 6, 2015 15:50
-
-
Save mcintyre321/ff67ffa8e2f0c8ef86da to your computer and use it in GitHub Desktop.
RazorHostFactory for debugging embedded resources
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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