zoukankan      html  css  js  c++  java
  • 使用MVC过滤器保存操作日志

    //定义过滤器

    public class  LogAttribute : ActionFilterAttribute
    {
    /// <summary>
    /// 以逗号间隔
    /// </summary>
    private readonly string _parameterNames;


    public BizActivityLogAttribute( string parameters)
    {

    _parameterNames = parameters;

    }
    public override void OnActionExecuted(ActionExecutedContext filterContext)
    {

    var _logTypeName = string.Format("{0}/{1}", filterContext.ActionDescriptor.ControllerDescriptor.ControllerName, filterContext.ActionDescriptor.ActionName);

    Dictionary<string, string> paramDic = new Dictionary<string, string>();

    foreach (var param in _parameterNames.Split(','))
    {
    var paramValue = filterContext.Controller.ValueProvider.GetValue(param);

    if (!paramDic.ContainsKey(param))
    {
    paramDic.Add(param, paramValue.AttemptedValue);
    }
    }

    //然后就可以使用Log4Net之类的存储参数了...
    }
    }

    //使用过滤器

    [LogAttribute( "msg,msgList")]
    public ActionResult GetMessage( [ModelBinder(typeof(JsonBinder<CMessage>))]CMessage msg,
    [ModelBinder(typeof(JsonBinder<List<CMessage>>))]List<CMessage> msgList
    )
    {

    return View();
    }

  • 相关阅读:
    Noe4j启动警告
    SpringBoot
    MySQL数据库 java SQL语句区分大小写分析
    day24 模块的语法
    day23 re模块
    day22 常用模块02 序列化
    day21 常用模块01
    day20 面向对象06 MRO和C3算法
    day19 面向对象05 约束
    day18 面向对象04 反射
  • 原文地址:https://www.cnblogs.com/zhshlimi/p/5557409.html
Copyright © 2011-2022 走看看