ASP.NET 母版页和视图状态
我希望提高我的网站的性能,并不是因为它的性能很差,而只是作为一般练习。 对于 ASP.NET 站点,通常的建议是尽可能删除视图状态。 我相信这可以通过页面上的每个控件单独或整个页面来完成。
我的问题是,如果我禁用页面视图状态,这会停止母版页上控件的视图状态(据我所知,母版页实际上是页面上的控件)。
I am looking to improve the performance of my site, not because it is performing badly but just as a general exercise. The usual suggestion for asp.net sites is to remove viewstate wherever possible. I believe this can be done by each control on a page separately or for the whole page.
My question is if I disable the page viewstate will this stop the viewstate of controls on a masterpage (as I understand it the masterpage is actually a control on the page).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
有一种简单的方法可以缩小所有视图状态。
步骤 1. 创建一个如下所示的新类:
步骤 2. 将
App_Browsers
文件夹添加到您的项目中。步骤 3. 在新的
App_Browsers
文件夹中,添加一个新的default.browser
文件,如下所示。<浏览器>
<浏览器 refID="默认">
<控制适配器>
<适配器controlType =“System.Web.UI.Page”adapterType =“[YourNamespaceGoesHere].SessionPageStateAdapter”/>
当您现在运行页面时,您应该会发现视图状态大小已下降到几个字节。 SessionPageStateAdapter 类在将视图状态提供给浏览器之前拦截视图状态并将其保存在服务器上的会话状态。 仍然发送到客户端的视图状态位只是一个标识符,用于在页面回发到服务器时重建原始视图状态。
There's an easy way to shrink all your viewstate.
Step 1. Create a new class that looks like this:
Step 2. Add an
App_Browsers
folder to your project.Step 3. In your new
App_Browsers
folder, add a newdefault.browser
file that looks like this.<browsers>
<browser refID="Default">
<controlAdapters>
<adapter controlType="System.Web.UI.Page" adapterType="[YourNamespaceGoesHere].SessionPageStateAdapter" />
</controlAdapters>
</browser>
</browsers>
When you run your pages now, you should find your viewstate size has dropped to a few bytes. The SessionPageStateAdapter class intercepts viewstate before it gets served to the browser and holds it in on the server in Session state. The bit of viewstate that still gets sent to the client is just an identifier that is used to reconstitute the original viewstate when the page gets posted back to the server.
是的,页面就是页面流的鼻祖。 因此,禁用页面的视图状态会将视图状态呈现从 OnInit 进程中剔除。 更好的问题是为什么禁用母版页的视图状态会产生相同的效果?
Yes, the page is the originator of the page flow. Thus, disabling viewstate for the page takes the viewstate rendering out of the OnInit process. A better question would be why does disabling the viewstate for the master page do the same?
在优化网站之前,请注意一下,您是否通过确保所有文件在发送之前都经过 gzip 压缩来优化服务器。
如果没有,这将在你开始修改页面之前给你带来很大的提升。
http://www.codinghorror.com/blog/archives/000059.html
Just a quick note on the side before optimising the site, have you optimised the server by making sure all the files are gzipped before being sent.
If not this will get you a nice boost before you even start tinkering with the page.
http://www.codinghorror.com/blog/archives/000059.html