ASP.NET:将 ViewState 移动到页面底部

ASP.NET: Moving ViewState to bottom of page(ASP.NET:将 ViewState 移动到页面底部)
本文介绍了ASP.NET:将 ViewState 移动到页面底部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将 ViewState 移动到页面底部

What are the latest and greatest ways to move ViewState to bottom of the page

这可以在 IHttpHandler 中完成吗?它可以在 web.config 中指定以拦截对*.aspx"的请求?

Can this be done in a IHttpHandler that can be specified in the web.config to intercept requests to "*.aspx"?

<httpHandlers>
    <add verb="*" path="*.aspx" type="MyApp.OptimizedPageHandler" />
<httpHandlers>

其他选项是,这可以在 IHttpModule 中完成,但性能不佳,因为它会拦截所有请求.

Other options is that this could be done in a IHttpModule, but that is not as performant, as it will intercept all requests.

也可以在派生自 PageMasterPage 类的类中完成,但这不是模块化.

Also it could be done in an a class deriving from the Page or MasterPage-class, but this is not as modular.

是否有任何绩效惩罚?

推荐答案

在进行一些研究后,我整理了这篇博文.

After conducting some research I put together this blog-post.

我通过创建一个 HttpModule 并应用一个 响应过滤器 来解决这个问题,它修改页面的输出并将 ViewState 移动到表格底部.

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.

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;
    }
    // [...]

这篇关于ASP.NET:将 ViewState 移动到页面底部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
how do i pass parameters to aspnet reportviewer(如何将参数传递给aspnet report查看器)
Bind multiple parameters from route and body to a model in ASP.NET Core(在ASP.NET Core中将路由和主体中的多个参数绑定到一个模型)
Custom model binding in AspNet Core WebApi?(AspNet Core WebApi中的自定义模型绑定?)
How to minify in .net core mvc view?(如何在.Net核心MVC视图中缩小?)