Skip to content

Instantly share code, notes, and snippets.

@jesulink2514
Created January 3, 2016 22:51
Show Gist options
  • Save jesulink2514/d2647c3f5acead6e31ce to your computer and use it in GitHub Desktop.
Save jesulink2514/d2647c3f5acead6e31ce to your computer and use it in GitHub Desktop.
AuditFilter.cs
using System.Linq;
using System.Web.Mvc;
using Microsoft.AspNet.Identity;
namespace AuditSample.Models
{
public class AuditFilter:FilterAttribute, IActionFilter
{
public void OnActionExecuting(ActionExecutingContext filterContext)
{
var model = filterContext.ActionParameters.FirstOrDefault(x=> x.Value is IAuditRequest).Value as IAuditRequest;
if (model == null) return;
model.Ip = filterContext.HttpContext.Request.UserHostAddress;
model.UserId = filterContext.HttpContext.User.Identity.GetUserId();
}
public void OnActionExecuted(ActionExecutedContext filterContext)
{
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment