• ASP.NET MVC操作日志


    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);
            }
    
        }
  • 相关阅读:
    禁用LinkButton的方法
    Windows Server2008R2中导入Excel
    Viewport
    Firefox模拟手机访问手机网站
    关闭ReSharper中的[ Use 'var' ]提示(Disable C# “var” Recommendation in ReSharper)
    浏览器中如何获取想要的offsetwidth、、、clientwidth、、offsetheight、、、clientheight。。。
    JS中关于clientWidth offsetWidth scrollWidth 等的含义的详细介绍
    base64编码解码js
    scrollTop如何实现click后页面过渡滚动到顶部
    如何快速获取当前链接?后面的内容,location.search、页面滚动
  • 原文地址:https://www.cnblogs.com/zengtianli/p/9844906.html
Copyright © 2020-2023  润新知