How can I load external layout files using RazorEngine?
I've been trying for days (really, days) to use "external" files (provided from a different server using an ashx handler) as layouts in Razor.
@{
Layou开发者_如何学Ct = "http://someServer/templates.ashx?path=/my/template.cshtml";
}
This gives me an error about the path having to be a virtual one.
I've tried everything I could think of: VirtualPathProviders
, custom RazorViewEngines
, etc.
Nothing helps, has anyone done this or can someone give me a hint?
Make a VirtualPathProvider
that handles virtual paths that start with a magic token and passes all other paths to its Previous
property.
For example:
public override VirtualFile GetFile(string virtualPath) {
if (virtualPath.StartsWith("~/MySpecialTemplateServer"))
return new MyServerVirtualFile(virtualPath);
else
return Previous.GetFile(virtualPath);
}
精彩评论