Skip to content

Instantly share code, notes, and snippets.

@caevyn
Last active December 14, 2015 18:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save caevyn/5133306 to your computer and use it in GitHub Desktop.
Save caevyn/5133306 to your computer and use it in GitHub Desktop.
Exclude sensitive form data from elmah logs
//in global.asax
void ErrorLog_Filtering(object sender, ExceptionFilterEventArgs e)
{
var ctx = e.Context as HttpContext;
if(ctx == null)
{
return;
}
ElmahSensitiveDataFilter.Apply(e, ctx);
}
public static class ElmahSensitiveDataFilter
{
public static void Apply(ExceptionFilterEventArgs e, HttpContext ctx)
{
var sensitiveFormData = ctx.Request.Form.AllKeys
.Where(key => key.Equals("password", StringComparison.OrdinalIgnoreCase)).ToList();
if (sensitiveFormData.Count == 0)
{
return;
}
var error = new Error(e.Exception, ctx);
sensitiveFormData.ForEach(k => error.Form.Set(k, "*****"));
Elmah.ErrorLog.GetDefault(null).Log(error);
e.Dismiss();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment