珂珂的个人博客 - 一个程序猿的个人网站

asp.net 4.0 RequestValidator 脚本攻击

为了防止sql攻击,asp.net有一个危险字符验证,可是我们在使用编辑器时却需要插入特殊字符。在2.0 中页面中加个 ValidateRequest=“false” 就可以了 但是在4.0 中 还需要改配置文件,在4.0 中,我们可以配置web.config
< httpRuntime maxRequestLength="2097151000" executionTimeout="30000000" requestValidationType="FYJ.Web.CustomRequestValidator,FYJ.Web" />

using System;
using System.Collections.Generic;
using System.Text;
using System.Web.Util;
using System.Web;
 
namespace FYJ.Web
{
public class CustomRequestValidator : RequestValidator
{
protected override bool IsValidRequestString(HttpContext context, string value, RequestValidationSource requestValidationSource, string collectionKey, out int validationFailureIndex)
{
 
validationFailureIndex = -1;
//if (requestValidationSource == RequestValidationSource.QueryString) //对查询字符串进行验证
//{
// if (value.Contains("<"))//检查是否包含<,当然也可以检查其他特殊符号,或者忽略某些特殊符号.
// {
// context.Response.Redirect("~/Error.aspx", true);//直接转到自定义的错误页面.
// return false;
// }
//}
 
//return base.IsValidRequestString(context, value, requestValidationSource, collectionKey, out validationFailureIndex);
return true;
}
}
}

 


上一篇:asp.net安全问题

下一篇:个人代码全部开源


0 评论

查看所有评论

给个评论吧