开发者

ASP.NET: Global hook in Response?

开发者 https://www.devze.com 2022-12-11 15:44 出处:网络
Is there any way to interc开发者_运维知识库ept all ASPX Page Responses? I\'d like to intercept all the pages served and inject a small JavaScript at the end of each. Yes, you can do this with a HttpMo

Is there any way to interc开发者_运维知识库ept all ASPX Page Responses? I'd like to intercept all the pages served and inject a small JavaScript at the end of each.


Yes, you can do this with a HttpModule.

http://aspnetresources.com/articles/HttpFilters.aspx

        /// <summary>
    /// Init is required from the IHttpModule interface
    /// see http://aspnetresources.com/articles/HttpFilters.aspx
    /// </summary>
    /// <param name="Appl"></param>
    public void Init(System.Web.HttpApplication app)
    {
        // Wire up the Response filter
        app.ReleaseRequestState += new EventHandler(InstallResponseFilter);

    }


This article might as well (your javascript can be within the footer): Add a header and footer control to all web pages in a web application, using HTTP module

Excerpts:

When developing the presentation of a web application, we typically follow a template structure for all the web pages. The template usually contains some sort of company logo and navigation in a header section, and some legal info and contact info in the footer section, etc. The HTML codes for these header and footer section are typically the same throughout the entire site, and may therefore need to be copied and pasted in every single web page. To avoid the HTML code for the header and footer section being replicated all over the place, we use the "include" directive to include a chunk of HTML code in every page.


There are several approaches to adding a footer, depending on the details of your requirements:

  1. An HttpModule. Depending on how the HttpModule is registered, you may need to check for a text/html MIME type in the output, to be sure you're dealing with an HTML page.
  2. A common page base class.
  3. A PageAdapter that you bind to all pages.
  4. A Master Page that you bind to all pages.
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号