惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

The Register - Security
The Register - Security
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
MyScale Blog
MyScale Blog
V
Visual Studio Blog
云风的 BLOG
云风的 BLOG
aimingoo的专栏
aimingoo的专栏
C
Check Point Blog
J
Java Code Geeks
大猫的无限游戏
大猫的无限游戏
L
LangChain Blog
Vercel News
Vercel News
阮一峰的网络日志
阮一峰的网络日志
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
S
Security @ Cisco Blogs
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
人人都是产品经理
人人都是产品经理
H
Hacker News: Front Page
L
Lohrmann on Cybersecurity
T
Troy Hunt's Blog
T
Threat Research - Cisco Blogs
A
About on SuperTechFans
T
Threatpost
AWS News Blog
AWS News Blog
Recent Commits to openclaw:main
Recent Commits to openclaw:main
T
Tor Project blog
Google Online Security Blog
Google Online Security Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
T
Tenable Blog
W
WeLiveSecurity
博客园 - 叶小钗
K
Kaspersky official blog
Y
Y Combinator Blog
T
The Blog of Author Tim Ferriss
Hugging Face - Blog
Hugging Face - Blog
M
MIT News - Artificial intelligence
Hacker News - Newest:
Hacker News - Newest: "LLM"
Engineering at Meta
Engineering at Meta
有赞技术团队
有赞技术团队
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
S
Secure Thoughts
小众软件
小众软件
D
Docker
爱范儿
爱范儿
C
Cyber Attacks, Cyber Crime and Cyber Security
N
News and Events Feed by Topic
S
Schneier on Security
博客园 - 三生石上(FineUI控件)
D
DataBreaches.Net

博客园 - 码 头

实测有效:Win11右键默认显示更多设置教程 netcore 并发锁 多线程中使用SemaphoreSlim HTML转义字符大全 .Net Core后台任务启停(BackgroundService) 常见的JavaScript的循环处理数据方法 Linux下.NET Core进程守护设置,解决SSH关闭后.NET Core服务无法访问的问题 记录 IIS 部署vue 项目步骤 AspNetCoreApi 跨域处理(CORS ) .NET CORE 使用Session报错:Session has not been configured for this application or request 小豆苗疫苗辅助搜索 日期函数(sql) 图片javascript缩小 c# DESEncrypt 加密、解密算法 汉字编码问题转换 二分法算法 最全的Resharper快捷键汇总 如何将数据库中的表导入到PowerDesigner中 修复IE9.0下PlaceHolder 属性问题js脚本 sql脚本查询日期时间段日期
MVC拦截器记录操作用户日志
码 头 · 2016-04-08 · via 博客园 - 码 头

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

 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("用户管理", "修改密码")] 就可以获取到用户操作的动作。