We have the hudrends of an .aspx and html file on our website, and we would like to add a little javascript at the end of each file. If I wanted to do this using the HttpModule (trying to learn something new), it would 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();
}
source
share