gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 19:16:20 27 4
gpt4 key购买 nike

我们在 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/

    27 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com