最近进行的MVC系统需要用到记录操作日志和过滤特殊字符的功能,如果每个action中都调用记录日志的方法就太麻烦了,所以根据需要结合mvc的过滤机制

写了个特殊字符验证与记录操作日志的公用类:

  public class CustomFilterAttribute : ActionFilterAttribute
{
public CustomFilterAttribute()
{
IsLog = false;
FilterSpecialChar = true;
} /// <summary>
/// 是否记录日志
/// </summary>
public bool IsLog { get; set; } /// <summary>
/// 是否过滤特殊字符
/// </summary>
public bool FilterSpecialChar { get; set; } /// <summary>
/// 登录用户
/// </summary>
public string UserName { get; set; } /// <summary>
/// 操作简介
/// </summary>
public string Message { get; set; } /// <summary>
/// action执行前特殊字符过滤
/// </summary>
/// <param name="filterContext"></param>
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
base.OnActionExecuting(filterContext); if (filterContext.ActionParameters.Count > )
{
if (filterContext.HttpContext.Request.IsAjaxRequest())
{
if (IsContainSpecialChar(filterContext.ActionParameters))
{
var json = new JsonResult();
json.Data = new { status = false, msg = "您输入的数据中包含特殊字符。" };
json.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
filterContext.Result = json;
}
}
else if (IsContainSpecialChar(filterContext.ActionParameters))
{
var ReturnUrl = "/Login/Index";
filterContext.Result = new RedirectResult(ReturnUrl);
}
} return;
} /// <summary>
/// action执行后记录日志
/// </summary>
/// <param name="filterContext"></param>
public override void OnActionExecuted(ActionExecutedContext filterContext)
{
base.OnActionExecuted(filterContext);
if (this.IsLog)
{
var ActionName = filterContext.ActionDescriptor.ActionName;
var Url = "/" + filterContext.ActionDescriptor.ControllerDescriptor.ControllerName + "/" + ActionName; //var loginInfo = (ViewModel.t_User_VModel)filterContext.HttpContext.Session["userMdl"];
string OperateIP = HttpContext.Current.Request.UserHostAddress; //登录用户
//if (loginInfo != null)
//{
// this.UserName = loginInfo.UserName;
//}
this.UserName = "测试";
Message = filterContext.Exception == null ? "成功" : "失败" + Message; new JiaSoftOTOSystem.BLL.OperateLog_BLL().AddOprateLog(UserName, OperateIP, Url, ActionName, Message);
}
} //public override void OnResultExecuting(ResultExecutingContext filterContext)
//{
// base.OnResultExecuting(filterContext);
// //filterContext.HttpContext.Response.Write("返回Result之前" + Message + "<br />");
//} //public override void OnResultExecuted(ResultExecutedContext filterContext)
//{
// base.OnResultExecuted(filterContext);
// //filterContext.HttpContext.Response.Write("返回Result之后" + Message + "<br />");
//} /// <summary>
/// 验证string类型参数中是否含有特殊字符
/// </summary>
/// <param name="paramters"></param>
/// <returns>有:true,没有:false</returns>
public bool IsContainSpecialChar(IDictionary<string, object> paramters)
{
bool bResult = false;
System.Text.StringBuilder strParam = new System.Text.StringBuilder();
foreach (var item in paramters)
{
if (item.Value != null)
{
Type types = item.Value.GetType();
if (types.Name.EndsWith("Model"))
{
System.Reflection.PropertyInfo[] ps = types.GetProperties();
foreach (PropertyInfo pi in ps)
{
object value = pi.GetValue(item.Value, null);//用pi.GetValue获得值
string name = pi.Name;//获得属性的名字,后面就可以根据名字判断来进行些自己想要的操作
//获得属性的类型,进行判断然后进行以后的操作,例如判断获得的属性是整数
if (value != null && value.ToString().Length > )
{
if (value.GetType() == typeof(string))
{
if (FilterSpecialChar && !bResult && Regex.IsMatch(value.ToString(), @"[~<>$%\^\+\&\\\/\?\|:\{}()';=]"))
{
bResult = true;
strParam.Append(name + "=" + value.ToString().Replace("'", "‘").Replace("\"", "").Replace("&", "&amp").Replace("<", "&lt").Replace(">", "&gt") + "|");
}
else if (IsLog)
{
strParam.Append(name + "=" + value + "|");
}
}
else if (IsLog && item.Value.GetType() == typeof(Guid) && item.Value.ToString() != Guid.Empty.ToString())
{
strParam.Append(name + "=" + value + "|");
}
else if (IsLog && (item.Value.GetType() == typeof(int) || item.Value.GetType() == typeof(decimal)) && item.Value.ToString() != "")
{
strParam.Append(name + "=" + value + "|");
}
else if (IsLog)
{
strParam.Append(name + "=" + value + "|");
}
}
}
}
else if (item.Value != null && item.Value.ToString().Length > )
{
if (item.Value.GetType() == typeof(string))
{
if (FilterSpecialChar && !bResult && Regex.IsMatch(item.Value.ToString(), @"[~<>$%\^\+\&\\\/\?\|:\{}()';=]"))
{
bResult = true;
strParam.Append(item.Key + "=" + item.Value.ToString().Replace("'", "‘").Replace("\"", "").Replace("&", "&amp").Replace("<", "&lt").Replace(">", "&gt") + "|");
}
else if (IsLog)
{
strParam.Append(item.Key + "=" + item.Value + "|");
}
}
else if (IsLog && item.Value.GetType() == typeof(Guid) && item.Value.ToString() != Guid.Empty.ToString())
{
strParam.Append(item.Key + "=" + item.Value + "|");
}
else if (IsLog && (item.Value.GetType() == typeof(int) || item.Value.GetType() == typeof(decimal)) && item.Value.ToString() != "")
{
strParam.Append(item.Key + "=" + item.Value + "|");
}
else if (IsLog)
{
strParam.Append(item.Key + "=" + item.Value + "|");
}
}
}
} this.Message = "。参数:" + strParam.ToString(); return false;
} }

调用方式如下:

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAowAAACzCAIAAACM4trQAAAfTElEQVR4nO2dz4smx3nH54+wjj76JF8NYyyDiRaBdclubPBJGx8MxlpB8GmECXjQ7pJALlICEQJJFx/EmgSRMEt83HWOWemQgNnVwQGFXYMCSWaTYDLvzNs5vKvemnp+1Leqq7ur+/1+aIZ+q5966qme7v72U/3roCOEEEJIkxzMHQAhhBBCdCjShBBCSKNQpAkhhJBGoUgTQgghjTKPSB8fHw8pJAPZHB5WrKIu8puIlubGg9v3lgVdJoSQ2ZlBpEdS6JblfK7YNoeH4RQt8u3lIr+hAvukguaW+5bUaULI4liJSLes0DtmidCRKD/97UXUmpyGHP9OQ4glGAweBiGENM7UIr2fCr1j+jhzRddKbS0pdfQSHB7HRTpZ6HcQFHVCCGmKxYu0Vben/xkuimyipVFhtCgqUX2q9ninaqGKLpi2qvZZ48z4SDvotkBxKcmEkEUzqUhPptBy3ikM//qF6rwjw7PfCqfmqb5IW7l1sjrYSu98SKaLZ9543wkhpEGWLdJOdUQ7cZEO3YIyPLtCd/mZdGhgqSnoNinSlrG8CB39TOr68GEAQghphOlEegyF9u2d9DecA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p999cL2pDYUe8FXntIWskMh5RHKzCbe9zt2SLcvk5i1LwF21zGfn7qTJ/d1HVkRWHRKVbybBNzDV0tov8P1I+nHaBX12Yh/cSaz6dk+wcL9EmpCVYWkbIWR65P5IkYabwR6IIoQ0S5SigbnjvsG11BQc7iaEEEIahSJNCCGENApFmhBCCGkUfk+aEEIIIWNBkSaEEEIahSJNCCGENApFmhBCCGkUijQhhBDSKBRpQgghpFEo0oQQQkijUKQJIYSQRqFIE0IIIY1CkSaEEEIahSJNCCGENApFmhBCCGkUijQhhBDSKBRpQgghpFEo0oQQQkijUKQJIYSQRvl/B+0DyH9ptRcAAAAASUVORK5CYII=" alt="" />

验证结果:如果包含特殊字符:如果是ajax请求则返回json,否则返回到错误页。

MVC 记录操作日志与过滤特殊字符的更多相关文章

  1. Appfuse:记录操作日志

    appfuse的数据维护操作都发生在***form页面,与之对应的是***FormController,在Controller中处理数据的操作是onSubmit方法,既然所有的操作都通过onSubmi ...

  2. Tomcat会话超时时怎样记录操作日志,满足安全审计要求

    众所周知.在实际的Web应用程序中,会话管理一般都採用Web容器会话管理功能. 使用Tomcat做Webserver也是如此,并且从安全的角度考虑,尽量避免去更改和干预Web容器的会话管理功能. To ...

  3. 使用SpringBoot AOP 记录操作日志、异常日志

    平时我们在做项目时经常需要对一些重要功能操作记录日志,方便以后跟踪是谁在操作此功能:我们在操作某些功能时也有可能会发生异常,但是每次发生异常要定位原因我们都要到服务器去查询日志才能找到,而且也不能对发 ...

  4. Spring aop 记录操作日志 Aspect

    前几天做系统日志记录的功能,一个操作调一次记录方法,每次还得去收集参数等等,太尼玛烦了.在程序员的世界里,当你的一个功能重复出现多次,就应该想想肯定有更简单的实现方法.于是果断搜索各种资料,终于搞定了 ...

  5. springboot springmvc拦截器 拦截POST、PUT、DELETE请求参数和响应数据,并记录操作日志

    1.操作日志实体类 @Document(collection = "operation_log") @Getter @Setter @ToString public class O ...

  6. MVC增加操作日志

    在后台管理中,有一些操作是需要增加操作日志的,尤其是对一些比较敏感的金额类的操作,比如商城类的修改商品金额.删除商品.赠送金额等人工的操作.日志中记录着相关操作人的操作信息,这样,出了问题也容易排查. ...

  7. .Net捕获网站异常信息记录操作日志

    第一步:在Global.asax文件下的Application_Error()中写入操作日志 /// <summary> /// 整个网站出现异常信息,都会执行此方法 /// </s ...

  8. 自定义日志注解 + AOP实现记录操作日志

      需求:系统中经常需要记录员工的操作日志和用户的活动日志,简单的做法在每个需要的方法中进行日志保存操作, 但这样对业务代码入侵性太大,下面就结合AOP和自定义日志注解实现更方便的日志记录   首先看 ...

  9. spring-boot-route(十七)使用aop记录操作日志

    在上一章内容中--使用logback管理日志,我们详细讲述了如何将日志生成文件进行存储.但是在实际开发中,使用文件存储日志用来快速查询问题并不是最方便的,一个优秀系统除了日志文件还需要将操作日志进行持 ...

随机推荐

  1. 分方式缓存常用的一致性hash是什么原理

    分方式缓存常用的一致性hash是什么原理 一致性hash是用来解决什么问题的?先看一个场景有n个cache服务器,一个对象object映射到哪个cache上呢?可以采用通用方法计算object的has ...

  2. HTML5 十大新特性(一)——语义标签

    说语义标签前先来理解下什么叫语义化,当下html是靠div+css来铸造页面的整体框架和结构的,通篇大量的div可读性极低,因此诞生了这些特殊的标签,简单地说就是见名知义,使页面更清晰,方便维护和开发 ...

  3. mysqld_safe启动报错 mysqld_safe The file /usr/local/mysql/bin/mysqld does not exist or is not executable

    报错(如下),但是使用mysqld直接启动没有问题. 150718 00:03:38 mysqld_safe Logging to '/var/log/mysqld.log'. 150718 00:0 ...

  4. 【原创】Mac os 10.10.3 安装xgboost

    大家用的比较多的是Linux和windows,基于Mac os的安装教程不多, 所以在安装的过程中遇到很多问题,经过较长时间的尝试,可以正常安装和使用, [说在前面]由于新版本的Os操作系统不支持op ...

  5. org.apache.commons.lang.StringUtils类

    org.apache.commons.lang.StringUtils类 本文摘自:(http://www.blogjava.net/japper/archive/2012/05/23/378946. ...

  6. asp.net mvc处理css和js版本问题

    当服务的修改了js和css内容后,发布到IIS服务器上,总是导致客户端内容显示不正确,原因是客户端存在缓存,还是加载的原来的js和css问题. 在css或js后面添加版本号,例如: <scrip ...

  7. redis入门指南-安装redis

    纸上得来终觉浅 绝知此事要躬行 Redis官方不支持window.微软发布了可在redis的分支.不建议使用 但我确实用了. win7 redis2.8.4  php5.6  apache2.4 ht ...

  8. c# windows编程控件学习-2

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  9. jquery替换URL参数值

    由于经常会用到替换URL参数值,而网上写的方法代码都太长了,所以在这里写了一个简单的方法,供大家使用. 说明: reLoad(参数名,参数值) function reLoad(p, v) { var ...

  10. Python的平凡之路(8)

    (本文是对平凡之路(7)的补充等) 一.动态导入模块 import importlib __import__('import_lib.metaclass') #这是解释器自己内部用的 #importl ...