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