void IActionFilter.OnActionExecuting(ActionExecutingContext filterContext) { HttpContext ctx = HttpContext.Current; if (ctx.Session["User"] == null) { filterContext.Result = new RedirectResult("~/Login/Index"); return; } var sessionEntity = ctx.Session["User"] as SessionEntity; using (YCEntities ycDb = new YCEntities()) { ActionLog log = new ActionLog() { ControllerName = filterContext.ActionDescriptor.ControllerDescriptor.ControllerName, Action = string.Concat(filterContext.ActionDescriptor.ActionName, " (Logged By: Custom Action Filter)"), IPAddress = GetLocalIPAddress(), CreatedDate = filterContext.HttpContext.Timestamp, UserId = sessionEntity.UserID }; ycDb.ActionLogs.Add(log); ycDb.SaveChanges(); base.OnActionExecuting(filterContext); } }