如何使用 RazorEngine 加载外部布局文件?
我已经尝试了几天(真的,几天)使用“外部”文件(使用 ashx 处理程序从不同的服务器提供)作为 Razor 中的布局。
@{
Layout = "http://someServer/templates.ashx?path=/my/template.cshtml";
}
这给了我一个关于路径必须是虚拟路径的错误。
我已经尝试了我能想到的一切:VirtualPathProviders
、自定义RazorViewEngines
等。
没有任何帮助,有人这样做过吗?或者有人可以给我提示吗?
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.
@{
Layout = "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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
创建一个
VirtualPathProvider
来处理以魔术令牌开头的虚拟路径,并将所有其他路径传递到其上一个
属性。例如:
Make a
VirtualPathProvider
that handles virtual paths that start with a magic token and passes all other paths to itsPrevious
property.For example: