Sanitizer provider is not configured in the web.config file. Ajax Control Toolkit and HtmlEditorExtender problems.

The Problem

Today I had a hard 2 hours, and if you have found this blog post, I bet we are in the same shoes.
I was working on a ASP .NET + windows azure project, and I needed the HtmlEditorExtender  control from the Ajax Control Toolkit. I was lucky to find a control for my needs. So far so good.
I've installed the toolkit with NuGet Package manager, it added a reference to the assembly to my web.config. I've used the following code where I needed the HtmlEditorExtender:


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

Just to see how this control works. As you can bet ajaxToolkit is the reference to the assembly.
I've hit F5 and bam this uglyness showed up:
 


Details

I've tried to search on the codeplex site of the project, but nothing was mentioned about this.
Just use it as it is. Yeah, right! I've searched on google about this problem,
and what I've found were mostly outdated blogs, sites, stackoverflow topics.
On the asp.net site of the project I've found this web.config file: 

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


It was similar to the web.config files found on stackoverflow, and IIS was complaining about not finding the AjaxControlToolkit assembly.
After many searches I've found this response on stackoverflow:
"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.".
Oh great! and were was this specified on the http://ajaxcontroltoolkit.codeplex.com/ ?
People don't use the blog of a developer to look for information about a project,
they use the main page of the project, that is the purpose of it, to find out why their
code is not working. And I don't need to mention that the Issue tracker had no
useful information about this.
 
Solution

The solution was to install HTML Agility Pack NuGet package. And make modifications to
the web.config, something 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>

Don't worry about the warning from VS about: "The element system.web has invalid child element..." it will work just fine.

Well, this is it. It is very hard to keep existing documentation up to date, as these technologies change every day, but at least they could made a list of things to keep in mind, to not let situations like this to happen. Nothing is worse than the lack of information when you are facing a problem.
I hope that you have found the solution to your problem in this post.
If you have any questions, suggestions or anything to say, you are welcome to post them as comments.
Until the next time, happy coding :)

Comments

  1. Hello,

    Many many thanks for this. I encountered similar problem and was running around sites to see the fix and as you mentioned all were outdated and none of them worked, until I found your site. I took a long break from programming and just now starting out again and have picked up .NET as my preferred platform. From now on, I will be visiting your site regularly to get more technology related updates.

    Thank you,

    Indu.

    ReplyDelete
  2. Thanks a lot!
    I've googled everywhere and this one actually help!
    Thanks. :D

    ReplyDelete
  3. Dude, thank you so much! I have been banging my head on this for hours!

    ReplyDelete
  4. It resolve the initial issue however giving me the following issue:

    Configuration Error
    Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.

    Parser Error Message: Could not load type 'AjaxControlToolkit.Sanitizer.HtmlAgilityPackSanitizerProvider'.

    Source Error:


    Line 116: <sanitizer> defaultProvider="HtmlAgilityPackSanitizerProvider"
    Line 117: <providers>
    Line 118: <add name="HtmlAgilityPackSanitizerProvider" type="AjaxControlToolkit.Sanitizer.HtmlAgilityPackSanitizerProvider"></add>
    Line 119: </providers>
    Line 120: </sanitizer>

    ReplyDelete
  5. Thank you very much, I don't know how many hours you saved me :)

    ReplyDelete
  6. Thanks to you for saving my lot of time and head ache. I also googled, there is hardly any mention of such things. In VS2008, the web.config simply do not support Sanitization tag.

    ReplyDelete
  7. Unfortunately this soltion does not work for VS 2012 .NET 4.5 projects.

    HTTP Error 500.19 - Internal Server Error
    The configuration section 'sanitizer' cannot be read because it is missing a section declaration.

    ReplyDelete
  8. I think you are having this problem with a newer version of the AjaxControlToolkit.
    Did you found a solution to your problem ?

    ReplyDelete
  9. Thanks a lot your solution helped me... Its so sad the ASP.Net site is not updated for these types of hiccups, perhaps we expecting too much. It would saves so many hours of searching.

    ReplyDelete
  10. This worked for me. 4.5 framework Sept 2013 AjaxToolKit. Thank you for putting in the extra effort!

    ReplyDelete
  11. Thanks a lot for saving my precious time.

    ReplyDelete
  12. Thanks so much ! I even had trouble with your solution but that´s because I had already added other XSS and Agility packages .. I just deleted and cleaned everything and followed your steps to the letter and it worked :) TY !

    ReplyDelete
  13. Am Getting This Error

    Unable to cast object of type 'System.Web.UI.HtmlControls.HtmlTextArea' to type 'System.Web.UI.WebControls.TextBox'.

    ReplyDelete
  14. Thank you thank you thank you. I am French kissing my dog and exposing myself to my neighbors im so exited about the solution

    ReplyDelete

Post a Comment

Popular posts from this blog

14 Sfaturi pentru programatori incepatori

DataTable to TreeView in C#, Displaying Hierarchies