错误“未在web.config文件中配置Sanitizer提供程序。”

时间:2013-03-01 04:29:19

标签: c# asp.net ajax

我想从ajaxtoolkit使用htmleditor。我从this link

下载了工具包

Ajax Control Toolkit .NET 3.5

但是收到错误“未在web.config文件中配置Sanitizer提供程序。如果您在公共网站上使用HtmlEditorExtender,请配置Sanitizer提供程序。否则,请将EnableSanitization属性设置为false。

的.aspx

<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
    </asp:ToolkitScriptManager>
    <asp:HtmlEditorExtender ID="HtmlEditorExtender1" runat="server" TargetControlID="txtBox1">
    </asp:HtmlEditorExtender>
    <asp:TextBox runat="server" ID="txtBox1" TextMode="MultiLine" Columns="50" Rows="10"
        Text="Hello <b>world!</b>" />

我搜索了很多网站..我得到以下代码作为添加到web.config中的解决方案 但是得到一个错误为“无法加载类型'AjaxControlToolkit.Sanitizer.AntiXssSanitizerProvider”。此外还有一行清理剂

<configSections>
        <sectionGroup name="system.web">
            <section name="sanitizer" requirePermission="false" type="AjaxControlToolkit.Sanitizer.ProviderSanitizerSection, AjaxControlToolkit"/>
        </sectionGroup>
    </configSections>
    <system.web>
        <sanitizer defaultProvider="AntiXssSanitizerProvider">
            <providers>
                <add name="AntiXssSanitizerProvider" type="AjaxControlToolkit.Sanitizer.AntiXssSanitizerProvider"></add>
            </providers>
        </sanitizer>
    </system.web>

AjaxControltoolkit

enter image description here

清洁剂提供者文件夹

enter image description here

3 个答案:

答案 0 :(得分:2)

使用以下行更改web.config中的sanitizer部分,然后尝试:

<sanitizer defaultProvider="HtmlAgilityPackSanitizerProvider">
    <providers>
        <add name="HtmlAgilityPackSanitizerProvider" type="AjaxControlToolkit.Sanitizer.HtmlAgilityPackSanitizerProvider"></add>
    </providers>
</sanitizer>

答案 1 :(得分:1)

您需要通过Nuget包管理器进行更新.. 所以这个问题都会自动解决。

安装如下在Visual Studio包管理器控制台中:

  1. PM&gt;安装包AjaxControlToolkit
  2. PM&gt;安装包AntiXSS
  3. PM&gt;安装包AjaxControlToolkit.HtmlEditor.Sanitizer
  4. PM&gt;安装包HtmlAgilityPack -Version 1.4.9
  5. 在以下位置添加新章节:

        <configuration>  
            <configSections>
            <section name="ajaxControlToolkit" type="AjaxControlToolkit.AjaxControlToolkitConfigSection, AjaxControlToolkit" />
    </configSections>        
    ....
            ...
    
        <runtime>
            <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    
              <dependentAssembly>
                <assemblyIdentity name="HtmlAgilityPack" publicKeyToken="bd319b19eaf3b43a" culture="neutral" />
                <bindingRedirect oldVersion="0.0.0.0-1.4.9.0" newVersion="1.4.9.0" />
              </dependentAssembly>
            </assemblyBinding>
          </runtime>
            <ajaxControlToolkit htmlSanitizer="AjaxControlToolkit.HtmlEditor.Sanitizer.DefaultHtmlSanitizer, AjaxControlToolkit.HtmlEditor.Sanitizer" />
        </configuration>  
    

答案 2 :(得分:0)

将AjaxControlToolkit.Binary.NET40.zip中的所有文件复制到bin文件夹中。

这是web.config中需要的配置:

<configuration>
  <configSections>
...
    <sectionGroup name="system.web">
      <section name="sanitizer" requirePermission="false" type="AjaxControlToolkit.Sanitizer.ProviderSanitizerSection, AjaxControlToolkit"/>
    </sectionGroup>

....

  <system.web>
    <sanitizer defaultProvider="HtmlAgilityPackSanitizerProvider">
      <providers>
        <add name="HtmlAgilityPackSanitizerProvider" type="AjaxControlToolkit.Sanitizer.HtmlAgilityPackSanitizerProvider"/>
      </providers>
    </sanitizer>

在你的aspx文件中:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="CommunitySafeApp.Start.WebForm1" %>

<%@ Register TagPrefix="asp" Namespace="AjaxControlToolkit" Assembly="AjaxControlToolkit"%>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>


<asp:ToolkitScriptManager runat="Server" />
<asp:TextBox
        ID="txtComments"
        TextMode="MultiLine"
        Columns="60"
        Rows="8"
        runat="server" />

<asp:HtmlEditorExtender
        TargetControlID="txtComments"
        runat="server" />

    </div>

    </form>
</body>
</html>