• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

ASP.NETMVC操作日志

原作者: [db:作者] 来自: [db:来源] 收藏 邀请
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);
        }

    }

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
asp.net运行时,报控件不存在发布时间:2022-07-10
下一篇:
Csharp:asp.netCheckBoxListdatabind发布时间:2022-07-10
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap