码迷,mamicode.com
首页 > Web开发 > 详细

使用MVC过滤器保存操作日志

时间:2016-06-03 21:28:40      阅读:252      评论:0      收藏:0      [点我收藏+]

标签:

 

//定义过滤器

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();
}

 

使用MVC过滤器保存操作日志

标签:

原文地址:http://www.cnblogs.com/zhshlimi/p/5557409.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!