.net 4.0 ValidateRequest
1、修改 web.config
<httpRuntime maxRequestLength=”102400 ” requestValidationType=”CustomRequestValidation” />
2、增加类
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Util;
namespace Globals
{
/// <summary>
/// Summary description for CustomRequestValidation
/// </summary>
public class CustomRequestValidation : RequestValidator
{
public CustomRequestValidation() { }
protected override bool IsValidRequestString(HttpContext context, string value, RequestValidationSource requestValidationSource, string collectionKey, out int validationFailureIndex)
{
//block script tags
var idx = value.ToLower().IndexOf(“<script”);
if (idx > -1)
{
validationFailureIndex = idx;
return false;
}
else
{
validationFailureIndex = 0;
return true;
}
}
}
}
这样更改也可以,但是有安全隐患
<configuration>
<system.web>
<httpRuntime requestValidationMode=”2.0″>
就是使用2.0版本的请求验证模式,就不会再报这个错了
http://www.cnblogs.com/losesea/archive/2012/05/20/2509359.html
这里说的比较详细。