博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
MVC拦截器记录操作用户日志
阅读量:4673 次
发布时间:2019-06-09

本文共 2013 字,大约阅读时间需要 6 分钟。

主要是用于记录用户操作动态,

1 public class OperationAttribute:ActionFilterAttribute 2 { 3 ///  4 /// 方法名称 5 ///  6 public string ActionName { get; set; } 7 ///  8 /// 控制器名称 9 /// 10 public string ControllerName { get; set; }11 /// 12 /// 方法参数13 /// 14 public string ActionParameters { get; set; }15 /// 16 /// 访问时间17 /// 18 public DateTime AccessDate { get; set; }19 /// 20 /// 登录用户21 /// 22 public string LoginName { get; set; }23 /// 24 /// 操作备注25 /// 26 public string Operationremark { get; set; }27 /// 28 /// 是否记录入库29 /// 30 public bool IsLog { get; set; }31 /// 32 /// 操作模块描述33 /// 34 public string ModuleName { get; set; }35 /// 36 /// 操作动作37 /// 38 public string Option { get; set; }39 40 /// 41 /// 操作人id42 /// 43 public int adminid { get; set; }44 /// 45 /// 操作人名46 /// 47 public string adminName { get; set; }48 49 public OperationAttribute()50 {51 this.AccessDate = DateTime.Now;52 this.IsLog = true;53 }54 55 /// 56 /// 57 /// 58 /// 操作模块描述59 /// 操作动作描述60 /// 其他备注61 public OperationAttribute(string moduleName, string option,string remark="")62 {63 this.AccessDate = DateTime.Now;64 this.IsLog = true;65 this.ModuleName = moduleName;66 this.Option = option;67 this.Operationremark = remark;68 }69 public override void OnActionExecuting(ActionExecutingContext filterContext)70 {71 if (this.IsLog)72 {73 //方法名称74 this.ActionName = filterContext.ActionDescriptor.ActionName;75 //控制器76 this.ControllerName = filterContext.ActionDescriptor.ControllerDescriptor.ControllerName;77 ///页面传递参数78 IDictionary
dic = filterContext.ActionParameters;79 var parameters = new System.Text.StringBuilder();80 foreach (var item in dic)81 {82 parameters.Append(item.Key + "=" + item.Value + "|^|");83 }84 this.ActionParameters = parameters.ToString();85 var userInfo = GetUserResultModel();86 87 //this.adminName = userInfo.userName;88 89 //this.adminid = userInfo.userid;90 91 //操作数据库记录92 93 94 }95 }

 

 

 

使用方法:

直接在action头上 加多特性[Operation("用户管理", "修改密码")] 就可以获取到用户操作的动作。

转载于:https://www.cnblogs.com/yjung/p/5368704.html

你可能感兴趣的文章
ASP.NET 安全认证(四)
查看>>
IE9+下如何让input的placeholder样式生效
查看>>
使用 web storage 制作简单留言本
查看>>
61组第二次团队作业
查看>>
利用jsonp实现跨域请求
查看>>
查看Oracle表中的指定记录在数据文件中的位置
查看>>
ServicePointManager.ServerCertificateValidationCallback 冲突的解决
查看>>
Notes on UNPv1 Ch.5
查看>>
Dubbo实战快速入门 (转)
查看>>
旅游电车
查看>>
Win32中文件的操作
查看>>
【分治】动态点分治 ([ZJOI2007]捉迷藏)
查看>>
「一入 Java 深似海 」系列课程
查看>>
技术胖Flutter第四季-19导航父子页面的跳转返回
查看>>
阶段1 语言基础+高级_1-3-Java语言高级_04-集合_03 斗地主案例(单列)_1_斗地主案例的需求分析...
查看>>
Unity 3D 正交相机(Orthographic)
查看>>
敏捷个人课后练习五主题:改变
查看>>
Lucas&&Exlucas
查看>>
Unity3D ARPG网络游戏编程实践
查看>>
UIAppearance
查看>>