有没有办法从当前应用程序外部加载母版页?
我正在构建一个环境原型,其中多个应用程序在同一服务器上运行,但它们都共享一个母版页。
是否可以从另一个应用程序加载母版页?在我的一个应用程序中,我有以下代码:
protected override void OnPreInit(EventArgs e)
{
base.OnPreInit(e);
this.MasterPageFile = "~/../MasterPages/Root.master";
}
其作用是将母版页设置为位于当前应用程序之外的文件。 (注意波浪号后面的“..”——所以我要转到当前应用程序的根目录,然后向上一个目录查找母版页。)
ASP 对此感到不满:
The virtual path '/MasterPages/Root.master' maps to another application, which is not allowed.
我知道这可能会受到压力事实上,它没有支持类,但是如果我的代码隐藏中没有任何内容,并且我选择不从任何内容继承我的母版页,那么整个内容都包含在“.master”文件中?
有什么办法可以做到这一点吗?
I'm prototyping an environment where multiple applications run on the same server, but they all share a master page.
Is it possible to load a master page from another application? In one of my applications, I have this code:
protected override void OnPreInit(EventArgs e)
{
base.OnPreInit(e);
this.MasterPageFile = "~/../MasterPages/Root.master";
}
What this does is set the master page to a file sitting outside my current application. (Note the ".." after the tilde -- so I'm going to the root of my current app, then stepping up a directory to find a master page.)
ASP is displeased with this:
The virtual path '/MasterPages/Root.master' maps to another application, which is not allowed.
I understand that it might be stressed out about the fact that there's no backing class for it, but what if I have nothing in the code-behind, and I choose not to inherit my master page from anything -- so the entire thing is contained in the ".master" file?
Is there any way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以考虑将虚拟目录映射到应用程序文件夹结构中,然后该目录可以同时映射到多个应用程序。
You might consider mapping a virtual directory into your apps folder structure, then that directory can be mapped to multiple applications at the same time.
只是想一下袖口,但是如果您在每个应用程序下创建一个映射到同一物理目录的虚拟目录会怎么样:
所以您可能有一个物理布局:
然后你将 IIS 设置为:
Just thinking of the cuff but what if you create a virtual directory under each application which maps to the same physical directory:
So you might have a physical layout of:
You'd then have IIS set up like:
我们使母版页变得非常通用。每个母版页都会使用 WebRequest 来捕获我们常见的请求马蹄形 html(或 .aspx)页面。
这种方法最困难的事情是我们必须在马蹄铁上放置标记。这些标记将指示应用程序可以替换什么以及放置其内容的位置。
We made our master page very generic. Each master page would use a WebRequest to capture our common horseshoe html (or .aspx) page.
The hardest thing about this approach is we had to put markers in the horseshoe. These markers would indicate what the application could replace and where to place its content.