CompilationMode=“Never”的 ASP.NET 嵌套母版页会带来灾难吗? ASP.NET 中的错误?
在开发一个相当大的 Web 应用程序项目时,我决定通过使用 CompilationMode="Never" @Page 属性标记一些页面和控件来获得一些新鲜空气。到目前为止一切顺利,按预期工作,然后事情就发生了。我将要解释的一个极端案例场景的表现出人意料,说得好听。这种情况就是嵌套母版页。
在继续之前先简单介绍一下。如果将顶部母版页标记为 CompilationMode="Always",并将其下方的所有其他页面标记为 CompilationMode="Never,您认为嵌套深度有多深”?不,它不是无限的,也不是 ASP.NET 具有的某个内部数字。它是2。为什么? - 我不知道,我希望你们中的一些聪明人能够启发我?
我附加了一个包含 5 个嵌套母版页的项目来演示我正在讨论的内容: 嵌套母版页 Web 应用程序测试项目< /a>.
另一个出人意料的极端情况 - 如果您有 5 个嵌套母版页,请将第二个母版页更改为 CompilationMode="Always",将所有其他页更改为 CompilationMode="Never"。您会注意到第三母版页被应用两次!
请帮助我了解我所做的事情是否不正确,或确认问题。
ASP.NET 运行时版本:2.0,.NET:3.5
编辑:
附加的项目将所有母版页设置为 CompilationMode="Never"。 ASPX 页面将根据需要显示。将第一个 master (Site.master) 更改为 CompilationMode="Always" 以查看我在说什么。
While working on a quite big web application project, I decided that it could gain a little bit of fresh air by marking some of the pages and controls with the CompilationMode="Never" @Page attribute. So far so good, working as expected and then it happened. A corner case scenario that I am going to explain behaved unexpectedly to put it nicely. This scenario is nested master pages.
A quick teaser before continuing. How deep nesting do you think you could go if you mark the top master page as CompilationMode="Always", and all others beneath it with CompilationMode="Never"? No, its not infinite, or some internal number that ASP.NET has. Its 2. Why? - I have no idea, and I was hoping some of you smart guys could enlighten me?
I have attached a project with 5 nested master pages to demonstrate what I am talking about: Nested Master Pages Web Application Test Project.
Another corner case that is working unexpectedly as well - if you have 5 nested master pages, change the second to have CompilationMode="Always" and all others to have CompilationMode="Never". You will notice that the 3rd master pages is being applied twice!
Please help me understand if something I am doing is incorrect, or confirm the issue.
ASP.NET Runtime Version: 2.0, .NET: 3.5
EDIT:
The project attached has all master pages set to CompilationMode="Never". The ASPX page displays as desired. Change the first master (Site.master) to have CompilationMode="Always" to see what I am talking about.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
更新(1/21/2010):好消息:经过更多调查,事实证明这个问题在 VS2010 中得到了修复。该修复是在 Beta 2 后进行的,因此它将成为下一个公共版本的一部分。我没有确切的日期,但应该不会太远。
是的,我似乎记得以前出现过这一点,并且确实一些涉及嵌套母版页和 CompilationMode="Never" 的场景被破坏了。
看看旧的邮件线程,我认为这只发生在某些组合上。看起来它已经被破坏了(其中NoCompile意味着compilationMode=never):
当时,我们没有修复这个问题,因为修复是非常重要的,并且场景是不常见。
请注意,当谈到 NoCompile 页面时,大部分好处是将其用于最终节点 aspx 页面,而不是母版页。一般来说,NoCompile 页面的运行速度比编译页面慢一些。它们的好处是它们没有第一次编译命中,并且使用更少的内存。此外,它们可以在内存压力下完全卸载。这就是为什么当您有大量端点页面时它们很有意义(Sharepoint 使用它们)。但在母版页上(大多数应用程序只有少数几个页面共享),这种好处是微乎其微的。当然,NoCompile 页面中不能有代码,这是很少有人使用它们的主要原因。
所以快速总结就是:你是对的,这是一个错误! :) 建议的解决方法是避免母版页的 CompilationMode=never 。
UPDATE (1/21/2010): Good news: after more investigation, it turns out that this issue was fixed in VS2010. The fix was made post Beta 2, so it will be part of the next public build. I don't have an exact date, but it should not be too far out.
Yes, I seem to recall this coming up before, and indeed some scenarios involving nester master pages and CompilationMode="Never" are broken.
Looking at an old mail thread, I think it only happens for certain combinations. It looks like it’s broken for (where NoCompile means compilationMode=never):
At the time, we did not fix this because the fix was non trivial and the scenario is not common.
Note that when it comes to NoCompile pages, most of the benefit is using it for end node aspx pages, and not master pages. Generally, NoCompile pages run a bit slower than compiled pages. Their benefit is that they don't have a first time compile hit, and they use less memory. Also, they can be fully unloaded under memory pressure. That's why they make good sense when you have a super large number of end point pages (Sharepoint uses them). But on master pages (where most apps only have a small number shared by many pages), that benefit would be minimal. And of course you can't have code in NoCompile pages, which is the main reason that few people use them.
So the quick summary is: you're right, it's a bug! :) And the recommended workaround is to avoid CompilationMode=never for master pages.