We've got hudrends of ASPX and HTML file in our site, and would like to inject a small JavaScript at the end of each file. If I wanted to do this using and HttpModule (trying to learn something new), would this do--are there any glaring problems?
public void Init(HttpApplication context)
{
context.BeginRequest += new EventHandler(context_BeginRequest);
}
void context_BeginRequest(object sender, EventArgs e)
{
var context = HttpContext.Current;
if (!isAspxOrHtmlFile(context.Request.Path)
{
return;
}
var javascript = ...
using (var writer = new StringWriter())
{
context.Server.Execute(context.Request.Path, writer);
context.Response.ContentType = "text/html";
context.Response.Write(writer.GetStringBuilder().ToString() + javascript);
}
context.Response.End();
}