MVC拦截器记录操作用户日志
主要是用于记录用户操作动态,
public class OperationAttribute:ActionFilterAttribute
{
/// <summary>
/// 方法名称
/// </summary>
public string ActionName { get; set; }
/// <summary>
/// 控制器名称
/// </summary>
public string ControllerName { get; set; }
/// <summary>
/// 方法参数
/// </summary>
public string ActionParameters { get; set; }
/// <summary>
/// 访问时间
/// </summary>
public DateTime AccessDate { get; set; }
/// <summary>
/// 登录用户
/// </summary>
public string LoginName { get; set; }
/// <summary>
/// 操作备注
/// </summary>
public string Operationremark { get; set; }
/// <summary>
/// 是否记录入库
/// </summary>
public bool IsLog { get; set; }
/// <summary>
/// 操作模块描述
/// </summary>
public string ModuleName { get; set; }
/// <summary>
/// 操作动作
/// </summary>
public string Option { get; set; } /// <summary>
/// 操作人id
/// </summary>
public int adminid { get; set; }
/// <summary>
/// 操作人名
/// </summary>
public string adminName { get; set; } public OperationAttribute()
{
this.AccessDate = DateTime.Now;
this.IsLog = true;
} /// <summary>
///
/// </summary>
/// <param name="moduleName">操作模块描述</param>
/// <param name="option">操作动作描述</param>
/// <param name="remark">其他备注</param>
public OperationAttribute(string moduleName, string option,string remark="")
{
this.AccessDate = DateTime.Now;
this.IsLog = true;
this.ModuleName = moduleName;
this.Option = option;
this.Operationremark = remark;
}
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
if (this.IsLog)
{
//方法名称
this.ActionName = filterContext.ActionDescriptor.ActionName;
//控制器
this.ControllerName = filterContext.ActionDescriptor.ControllerDescriptor.ControllerName;
///页面传递参数
IDictionary<string, object> dic = filterContext.ActionParameters;
var parameters = new System.Text.StringBuilder();
foreach (var item in dic)
{
parameters.Append(item.Key + "=" + item.Value + "|^|");
}
this.ActionParameters = parameters.ToString();
var userInfo = GetUserResultModel(); //this.adminName = userInfo.userName; //this.adminid = userInfo.userid; //操作数据库记录 }
}
使用方法:
直接在action头上 加多特性[Operation("用户管理", "修改密码")] 就可以获取到用户操作的动作。
MVC拦截器记录操作用户日志的更多相关文章
- spring mvc 通过拦截器记录请求数据和响应数据
spring mvc 能过拦截器记录请求数据记录有很多种方式,主要有以下三种: 1:过滤器 2:HandlerInterceptor拦截器 3:Aspect接口控制器 但是就我个人所知要记录返回的数据 ...
- spring mvc 拦截器的使用
Spring MVC 拦截器的使用 拦截器简介 Spring MVC 中的拦截器(Interceptor)类似于 Servler 中的过滤器(Filter).用于对处理器进行预处理和后处理.常用于日志 ...
- mvc拦截器
在ASP.NET MVC中,有三种拦截器:Action拦截器.Result拦截器和Exception拦截器.这里说的是第一种和第三种.其实所谓的ASP.NET MVC拦截器,也没什么神秘的,就是一个普 ...
- 【Java Web开发学习】Spring MVC 拦截器HandlerInterceptor
[Java Web开发学习]Spring MVC 拦截器HandlerInterceptor 转载:https://www.cnblogs.com/yangchongxing/p/9324119.ht ...
- Spring Boot 2.X(九):Spring MVC - 拦截器(Interceptor)
拦截器 1.简介 Spring MVC 中的拦截器(Interceptor)类似于 Servlet 开发中的过滤器 Filter,它主要用于拦截用户请求并作相应的处理,它也是 AOP 编程思想的体现, ...
- 写的太细了!Spring MVC拦截器的应用,建议收藏再看!
Spring MVC拦截器 拦截器是Spring MVC中强大的控件,它可以在进入处理器之前做一些操作,或者在处理器完成后进行操作,甚至是在渲染视图后进行操作. 拦截器概述 对于任何优秀的MVC框架, ...
- SSM(spring mvc+spring+mybatis)学习路径——2-2、spring MVC拦截器
目录 2-2 Spring MVC拦截器 第一章 概述 第二章 Spring mvc拦截器的实现 2-1 拦截器的工作原理 2-2 拦截器的实现 2-3 拦截器的方法介绍 2-4 多个拦截器应用 2- ...
- Spring MVC拦截器配置
Spring MVC拦截器配置 (1)自定义拦截器 package learnspringboot.xiao.other; import org.springframework.web.servlet ...
- 对于Spring MVC 拦截器的一些了解
Spring MVC 拦截器的执行顺序 应用场景 假设请求 localhost:8080/ 则要求直接重定向到 localhost:8080/login ; 定义拦截器顺序 permission lo ...
随机推荐
- cs11_c++_lab7
wcount.cc #include <iostream> #include <map> #include <string> #include <algori ...
- react在jsx语法中实现for循环
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script sr ...
- NHibernate系列文章二十二:NHibernate查询之HQL查询(附程序下载)
摘要 NHibernate提供了多种查询方式,最早的HQL语言查询.Criteria查询和SQL Query,到NHibernate 3.0的Linq NHibernate,NHIbernate 4. ...
- Centos安装lnmp环境
1:查看环境: [root@10-4-14-168 html]# cat /etc/redhat-release CentOS release 6.5 (Final) 2:关掉防火墙 [root@10 ...
- OpenVZ VPS加速方案–Final Speed
body,td { font-family: 微软雅黑; font-size: 10pt } OpenVZ VPS加速方案–Final Speed OpenVZ VPS加速方案–Final Spe ...
- php:微信公众号token验证失败原因、验证码显示不出来的问题
ob_clean(); 问题描述: 用微信官方提供的demo验证token是成功的,但是放到自己网站的框架上进行token验证老是提示"token验证失败",经过检查(用生成日志的 ...
- git 忽视大小写
git config core.ignorecase false http://stackoverflow.com/questions/3011625/git-mv-and-only-change-c ...
- 21.2 Partitioning Types
分区类型: range:根据列值得一个给定的范围 list:和range相似,除了分区被选择基于的列被匹配在一个被设定为分离的值 hash 基于列组成的表达式返回的非负值 key 相似hash ,除 ...
- Highcharts 在低版本 IE 上使用注意事项
来源:https://segmentfault.com/a/1190000004272693 很多人经常遇到图表在主流浏览器上运行正常,在低版本IE(包括IE6.IE7.IE8等)下运行出错(图表显示 ...
- 展开、收起div的jQuery代码
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...