public void OnActionExecuting(ActionExecutingContext filterContext) { // Don't show filter multiple times when using Html.RenderAction or Html.Action. if (filterContext.IsChildAction == true) { return; } // Action trace centralyzed ApplicationTracer.ApplicationTrace(System.Diagnostics.TraceLevel.Info, this.GetType(), filterContext.Controller.ToString(), filterContext.ActionDescriptor.ActionName, "Child action", null); }
void IAuthenticationFilter.OnAuthenticationChallenge(AuthenticationChallengeContext filterContext) { string Name = filterContext.HttpContext.User.Identity.Name; var user = filterContext.HttpContext.User; if (user == null || !user.Identity.IsAuthenticated) { filterContext.Result = new HttpUnauthorizedResult(); } else { string controllerName = filterContext.RouteData.Values["controller"].ToString(); string actionName = filterContext.RouteData.Values["action"].ToString(); // Authentication challenge trace centralyzed ApplicationTracer.ApplicationTrace(System.Diagnostics.TraceLevel.Info, this.GetType(), controllerName, actionName, "OnAuthenticationChallenge", null); } }
public override void OnException(ExceptionContext filterContext) { if (filterContext.ExceptionHandled || !filterContext.HttpContext.IsCustomErrorEnabled) { //((Controller)filterContext.Controller).ModelState.AddModelError("",filterContext.Exception.InnerException.InnerException.Message); //filterContext.ExceptionHandled = true; return; } if (new HttpException(null, filterContext.Exception).GetHttpCode() != 500) { return; } if (!ExceptionType.IsInstanceOfType(filterContext.Exception)) { return; } var controllerName = (string)filterContext.RouteData.Values["controller"]; var actionName = (string)filterContext.RouteData.Values["action"]; var model = new HandleErrorInfo(filterContext.Exception, controllerName, actionName); // if the request is AJAX return JSON else view. if (filterContext.HttpContext.Request.Headers["X-Requested-With"] == "XMLHttpRequest") { filterContext.Result = new JsonResult { JsonRequestBehavior = JsonRequestBehavior.AllowGet, Data = new { error = true, message = filterContext.Exception.Message } }; } else { filterContext.Result = new ViewResult { ViewName = View, MasterName = Master, ViewData = new ViewDataDictionary <HandleErrorInfo>(model), TempData = filterContext.Controller.TempData }; } ApplicationTracer.SignalExceptionToElmahAndTrace(filterContext.Exception, this.GetType(), controllerName, actionName); // log the error using log4net. // _logger.Error(filterContext.Exception.Message, filterContext.Exception); filterContext.ExceptionHandled = true; filterContext.HttpContext.Response.Clear(); filterContext.HttpContext.Response.StatusCode = 500; filterContext.HttpContext.Response.TrySkipIisCustomErrors = true; }