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

 1 public class OperationAttribute:ActionFilterAttribute
 2 {
 3 /// <summary>
 4 /// 方法名称
 5 /// </summary>
 6 public string ActionName { get; set; }
 7 /// <summary>
 8 /// 控制器名称
 9 /// </summary>
10 public string ControllerName { get; set; }
11 /// <summary>
12 /// 方法参数
13 /// </summary>
14 public string ActionParameters { get; set; }
15 /// <summary>
16 /// 访问时间
17 /// </summary>
18 public DateTime AccessDate { get; set; }
19 /// <summary>
20 /// 登录用户
21 /// </summary>
22 public string LoginName { get; set; }
23 /// <summary>
24 /// 操作备注
25 /// </summary>
26 public string Operationremark { get; set; }
27 /// <summary>
28 /// 是否记录入库
29 /// </summary>
30 public bool IsLog { get; set; }
31 /// <summary>
32 /// 操作模块描述
33 /// </summary>
34 public string ModuleName { get; set; }
35 /// <summary>
36 /// 操作动作
37 /// </summary>
38 public string Option { get; set; }
39 
40 /// <summary>
41 /// 操作人id
42 /// </summary>
43 public int adminid { get; set; }
44 /// <summary>
45 /// 操作人名
46 /// </summary>
47 public string adminName { get; set; }
48 
49 public OperationAttribute()
50 {
51 this.AccessDate = DateTime.Now;
52 this.IsLog = true;
53 }
54 
55 /// <summary>
56 /// 
57 /// </summary>
58 /// <param name="moduleName">操作模块描述</param>
59 /// <param name="option">操作动作描述</param>
60 /// <param name="remark">其他备注</param>
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<string, object> 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("用户管理", "修改密码")] 就可以获取到用户操作的动作。

posted on 2016-04-08 16:33  码 头  阅读(3838)  评论(8编辑  收藏  举报