Could not load type 'AjaxControlToolkit.Sanitizer.AntiXssSanitizerProvider'.

Idrees Khan picture Idrees Khan · Aug 18, 2012 · Viewed 18.4k times · Source

I tried to use htmleditorextender but I am getting error. below are my settings

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

<asp:TextBox runat="server" ID="textBoxGalleryUrl" CssClass="cstmtxtclr" />
<asp:HtmlEditorExtender ID="HtmlEditorExtender1" runat="server" TargetControlID="textBoxGalleryUrl"></asp:HtmlEditorExtender>

My web.conf settings are;

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

  <system.web>
    <!--<httpRuntime requestValidationMode="2.0"/>-->
    <compilation debug="true" targetFramework="4.0"/>

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

I have the following dlls in my bin folder;

AntiXSSLibrary.dll
SanitizerProviders.dll
HtmlSanitizationLibrary.dll

But I still get this error;

Could not load type 'AjaxControlToolkit.Sanitizer.AntiXssSanitizerProvider'.

Why I am getting this error?

Answer

bertzzie picture bertzzie · Aug 20, 2012

Using AntiXss as the default sanitizer is no longer supported as of June 2012. From the official announcement, apparantely the new version of AntiXss breaks too many things.

To use AjaxControlToolkit with HTML Agility Pack you first need to install the pacakge using Nuget (instruction).

Then you can use HTML Agility Pack as your sanitizer by modifying your web.config like this:

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

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

Hope this helps.