Skip to content

Instantly share code, notes, and snippets.

@nickfloyd
Created April 17, 2012 19:26
HttpModule for grabbing status code at the end of the request
Code that goes in the Web.Config inside the configuration node:
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<modules runAllManagedModulesForAllRequests="true">
<remove name="_9569.StatusCodeModule" />
<add name="StatusCodeModule" type="_9569.StatusCodeModule" />
</modules>
</system.webServer>
StatusCodeModule.cs code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace _9569
{
public class StatusCodeModule : IHttpModule {
public StatusCodeModule(){}
public void Dispose() { }
public void Init(System.Web.HttpApplication context)
{
context.AuthenticateRequest += new EventHandler(context_AuthenticateRequest);
context.EndRequest += new EventHandler(context_EndRequest);
}
void context_AuthenticateRequest(object sender, EventArgs e) {
//Authenticate
}
void context_EndRequest(object sender, EventArgs e) {
System.Web.HttpApplication app = (System.Web.HttpApplication)sender;
//Store status code here
int statusCode = HttpContext.Current.Response.StatusCode;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment