public void OnException(ExceptionContext filterContext) { try { if (filterContext.Exception is SemPermissaoException) { filterContext.Result = new RedirectToRouteResult( new RouteValueDictionary { { "controller", "Dashboards" }, { "action", "SemPermissao" } }); filterContext.ExceptionHandled = true; } if (!Directory.Exists(FILE_EXCEPTION_LOG)) { Directory.CreateDirectory(FILE_EXCEPTION_LOG); } ExceptionToFile(filterContext.Exception); } catch (Exception e) { var db = new ProjetoBaseContext(); Log log = new Log(); log.nomeUsuario = "EXCEPTION_SISTEMA"; log.menu = "EXCEPTION_DURANTE_EXCEPTION"; log.opcao = e.Message + "<br><br>" + e.StackTrace; log.data = DateTime.Now; db.Log.Add(log); db.SaveChanges(); } }
/// <summary> /// Retorna o contexto do entity framework, trabalhando com um context por request /// </summary> /// <returns></returns> public static ProjetoBaseContext getProjetoBaseContext() { if (HttpContext.Current.Session["ProjetoBaseContext"] == null) { var db = new ProjetoBaseContext(); HttpContext.Current.Session["ProjetoBaseContext"] = db; } return((ProjetoBaseContext)HttpContext.Current.Session["ProjetoBaseContext"]); }