加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

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

发布时间:2020-12-16 06:59:12 所属栏目:asp.Net 来源:网络整理
导读:我们在sitecore中有一个文本框,允许用户搜索内容.这会回发到服务器,它会关闭,进行搜索并返回一些结果(在屏幕上显示它们). 当我输入一些狡猾的东西,例如一些标记我希望得到一个.net异常: A potentially dangerous Request.QueryString value was detected fr
我们在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,它指示PreprocessRequest管道中的SuppressFormValidation处理器可能导致您遇到此问题.

这是确定的“违规”代码:

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)中的验证.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读