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:
- 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.
- A common page base class.
- A PageAdapter that you bind to all pages.
- A Master Page that you bind to all pages.
精彩评论