ASP.NET:将ViewState移至页面底部 [英] ASP.NET: Moving ViewState to bottom of page
问题描述
将ViewState移至页面底部的最新和最大方法是什么
可以在 web.config 中指定的 IHttpHandler 中完成此操作,以拦截对"* .aspx"的请求吗?
< httpHandlers><添加动词="*" path ="*.aspx" type ="MyApp.OptimizedPageHandler"/>< httpHandlers>
其他选择是可以在 IHttpModule 中完成此操作,但这不是性能优异,因为它将拦截所有请求.
也可以在源自 Page 或 MasterPage 类的类中完成,但这不是模块化.
对此有任何性能惩罚吗?
进行了一些研究之后,我整理了 Other options is that this could be done in a IHttpModule, but that is not as performant, as it will intercept all requests. Also it could be done in an a class deriving from the Page or MasterPage-class, but this is not as modular. Are there any performance penalties to this? After conducting some research I put together this blog-post. I solved the issue by creating a HttpModule and applying a Response Filter, which modifies the output of the page and moves the ViewState to the bottom of the form.
这篇关于ASP.NET:将ViewState移至页面底部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!<httpHandlers>
<add verb="*" path="*.aspx" type="MyApp.OptimizedPageHandler" />
<httpHandlers>
public class ViewStateSeoHttpModule : IHttpModule {
public void Init(HttpApplication context) {
context.BeginRequest += new EventHandler(BeginRequest);
}
private void BeginRequest(object sender, EventArgs e) {
HttpApplication application = sender as HttpApplication;
bool isAspNetPageRequest = GetIsAspNetPageRequest(application);
if(isAspNetPageRequest) {
application.Context.Response.Filter =
new ViewStateSeoFilter(application.Context.Response.Filter);
}
}
private bool GetIsAspNetPageRequest(HttpApplication application) {
bool isAspNetPageRequest = application.Context.Handler is System.Web.UI.Page;
return isAspNetPageRequest;
}
// [...]