chr*_*dev 5 asp.net sitecore sitecore6
我们在sitecore中有一个文本框,允许用户搜索内容.这会回发到服务器,它会关闭,进行搜索并返回一些结果(在屏幕上显示它们).
当我输入一些狡猾的东西时,例如一些标记,我希望收到一个.net异常:
A potentially dangerous Request.QueryString value was detected from the client (q="<img src="http://www...").
Run Code Online (Sandbox Code Playgroud)
据我了解,这是自ASP.NET v1.1以来的默认行为.然后在v4.0中,它仍然是默认值,只是将其扩展到所有请求(不仅仅是网页).
所以问题如下:
1. how have sitecore disabled this?
2. what can I do to re-enable this globally (i.e. not on a per page basis)?
Run Code Online (Sandbox Code Playgroud)
我注意到web.config中有一部分像这样开始:
<!-- Continue to run Sitecore without script validations -->
<pages validateRequest="false" controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID">
Run Code Online (Sandbox Code Playgroud)
你回答了自己的问题.以下是您的问题的答案:
在Sitecore中,默认值web.config
为此设置
<pages validateRequest="false" ... />
要将其打开,请将其设置为 true
此外,您可以查看此博客文章,其中指出管道中的SuppressFormValidation
处理器PreprocessRequest
可能导致您遇到此问题.
这是确定的"违规"代码:
namespace Sitecore.Pipelines.PreprocessRequest
{
public class SuppressFormValidation : PreprocessRequestProcessor
{
public override void Process(PreprocessRequestArgs args)
{
Assert.ArgumentNotNull(args, "args");
try
{
NameValueCollection form = args.Context.Request.Form;
}
catch (HttpRequestValidationException exception)
{
if (!args.Context.Request.RawUrl.StartsWith("/sitecore/shell/", StringComparison.InvariantCultureIgnoreCase))
{
Log.Error(exception.Message, exception, this);
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
博客文章中包含新代码,您可以将其替换为仅禁止Sitecore shell(后端GUI)中的验证.