在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
public class OperationLogAttribute : ActionFilterAttribute { public override void OnActionExecuted(ActionExecutedContext filterContext) { var controllerName = filterContext.ActionDescriptor.ControllerDescriptor.ControllerName; var actionName = filterContext.ActionDescriptor.ActionName; //检测是否登录控制器 var isAjaxRequest = filterContext.RequestContext.HttpContext.Request.IsAjaxRequest(); //页面加载 if (isAjaxRequest) { //过滤主页请求 if (filterContext.RequestContext.HttpContext.Request.RequestType.Equals("Post", StringComparison.OrdinalIgnoreCase)) { //获取数据去去掉 if (!controllerName.Equals("Login", StringComparison.OrdinalIgnoreCase) && !controllerName.Equals("ClientLogin", StringComparison.OrdinalIgnoreCase) && !controllerName.Equals("Leader", StringComparison.OrdinalIgnoreCase) && !controllerName.Equals("Home", StringComparison.OrdinalIgnoreCase) && !actionName.Equals("GetClientDataJson", StringComparison.OrdinalIgnoreCase)) { //请求数据 filterContext.RequestContext.HttpContext.Request.InputStream.Position = 0; var byts = new byte[filterContext.RequestContext.HttpContext.Request.InputStream.Length]; filterContext.RequestContext.HttpContext.Request.InputStream.Read(byts, 0, byts.Length); var req = System.Text.Encoding.Default.GetString(byts); //请求文本 req = filterContext.RequestContext.HttpContext.Server.UrlDecode(req); //请求地址 var reqUrl = filterContext.RequestContext.HttpContext.Request .AppRelativeCurrentExecutionFilePath; //返回结果 var content = ""; if (filterContext.Result != null) { content = "执行成功"; } else { content = filterContext.Exception.Message + "," + filterContext.Exception.Source; } //获得用户信息 var opr = OperatorProvider.Provider.Current(); var f_modelid = SystemInfo.CurrentModuleId; var f_module = new ModuleBLL().GetEntity(f_modelid).F_FullName; var f_executeResult = filterContext.Exception == null ? 1 : 0; //异步执行保存 Task.Factory.StartNew(() => { #region 构造日志实体 LogEntity logEntity = new LogEntity(); logEntity.F_CategoryId = 3; logEntity.F_OperateTypeId = ((int)OperationType.Submit).ToString(); logEntity.F_OperateType = EnumAttribute.GetDescription(OperationType.Submit); logEntity.F_ExecuteResult = f_executeResult; logEntity.F_OperateAccount = opr.Account; logEntity.F_OperateUserId = opr.UserId; logEntity.F_ExecuteResultJson = string.Format("执行结果:{0}",content); logEntity.F_ModuleId = f_modelid; logEntity.F_Module = f_module; logEntity.F_Description = string.Format("执行操作:{0},请求:{{{1}}}", reqUrl, req); #endregion try { logEntity.WriteLog(); } catch (Exception e) { // ignored } }); } } } base.OnActionExecuted(filterContext); } }
|
请发表评论