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

标签 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">

最佳答案

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

  • 在 Sitecore 中默认 web.config随此设置为 <pages validateRequest="false" ... />
  • 要打开它,请将其设置为 true

  • 另外,你可以看看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)中的验证。

    关于asp.net - 请求验证 - 在 SiteCore 中如何以及为何禁用它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9114276/

    相关文章:

    Sitecore 内容树架构

    c# - 视觉区分 Sitecore 克隆

    ASP.NET WebApi - HttpClient - 找不到方法

    Sitecore:如何在通用链接字段中输入类

    .net - 保持 Sitecore Lucene 索引最新

    c# - 如何以编程方式填充 Sitecore 项目(添加项目和字段)?

    asp.net - 在代码隐藏中使用 vb.net 在表中隐藏 tr 或 td

    c# - 如何在多个标签中打印sqldatareader的一列所有数据?

    javascript - 设置一天的 CSS 设计?

    sitecore - 使用 Sitecore Rocks 进行批量插入