如何使用 RazorEngine 加载外部布局文件?

发布于 2024-11-18 20:37:51 字数 329 浏览 6 评论 0原文

我已经尝试了几天(真的,几天)使用“外部”文件(使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

丢了幸福的猪 2024-11-25 20:37:51

创建一个VirtualPathProvider来处理以魔术令牌开头的虚拟路径,并将所有其他路径传递到其上一个属性
例如:

public override VirtualFile GetFile(string virtualPath) {
    if (virtualPath.StartsWith("~/MySpecialTemplateServer"))
        return new MyServerVirtualFile(virtualPath);
    else
        return Previous.GetFile(virtualPath);
}

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);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文