请求验证 - 在SiteCore中如何以及为何禁用它?

时间:2012-02-02 14:44:09

标签: asp.net sitecore sitecore6

我们在sitecore中有一个文本框,允许用户搜索内容。这会回发到服务器,它会关闭,进行搜索并返回一些结果(在屏幕上显示它们)。

当我输入狡猾的东西时,例如一些标记我希望得到一个.net异常:

A potentially dangerous Request.QueryString value was detected from the client (q="<img src="http://www..."). 

据我了解,that has been default behaviour since v1.1 of ASP.NET。然后在v4.0中,它仍然是默认的they just extended it to all requests(不仅仅是网页)。

所以问题如下:

1. how have sitecore disabled this?
2. what can I do to re-enable this globally (i.e. not on a per page basis)?

我注意到web.config的一部分是这样开始的:

<!-- Continue to run Sitecore without script validations -->
<pages validateRequest="false" controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID">

1 个答案:

答案 0 :(得分:5)

你回答了自己的问题。以下是您的问题的答案:

  1. 在Sitecore中,默认web.config附带此设置为 <pages validateRequest="false" ... />

  2. 要将其设为开启,请将其设为true

  3. 另外,您可以查看this blog post,表明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);
                    }
                }
            }
        }
    }
    

    博客文章中包含新代码,您可以将其替换为仅禁止Sitecore shell(后端GUI)中的验证。

相关问题