public void InsertLog(string msg, string type) { SysLog sl = new SysLog(); sl.LogId = Guid.NewGuid().ToString().Replace("-", ""); sl.LogMessage = msg; sl.LogIp = GetClientIp(); sl.LogType = type; sl.LogUrl = System.Web.HttpContext.Current.Request.Url.AbsolutePath; sl.CreateTime = DateTime.Now; sl.Creator = AuthTicket().SystemUserId; _sysLogServices.InsertAdd(sl); }
public override void OnException(ExceptionContext filterContext) { Exception error = filterContext.Exception; SysLog sl = new SysLog(); sl.LogType = "异常"; sl.LogId = Guid.NewGuid().ToString().Replace("-", ""); sl.LogMessage = error.Message; sl.LogUrl = HttpContext.Current.Request.RawUrl; sl.CreateTime = DateTime.Now; sl.Creator = "system"; var authCookie = System.Web.HttpContext.Current.Request.Cookies[FormsAuthentication.FormsCookieName]; if (authCookie != null) { if (!string.IsNullOrEmpty(authCookie.Value)) { var authTicket = FormsAuthentication.Decrypt(authCookie.Value); if (authTicket != null) { sl.Creator = authTicket.UserData; } } } _sysLogServices.InsertAdd(sl); var view = new ViewResult { ViewName = "~/Views/Shared/Error.cshtml", ViewData = { ["Error"] = "" } }; // filterContext.Result = view; filterContext.ExceptionHandled = true; //filterContext.Result = new RedirectToRouteResult("Login", new RouteValueDictionary()); //filterContext.Result = new RedirectResult("/Error/Show/"); }