主要是用于记录用户操作动态,
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 IDictionarydic = 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("用户管理", "修改密码")] 就可以获取到用户操作的动作。