由于HtmlEditorExtender没有报价系统,因此我编写了自己的报价系统。或者它有吗?
asp.net 4.5和ASP.NET AJAX Control Toolkit 16.1.0.0
2016年我们还没有白名单功能吗?
如需报价,我正在使用预标签。但是,版本16.1.0中的最新HtmlEditorExtender会对pre标记进行排序。它只删除包含预标记的部分。
我的意思是
<pre><pre>CeFurkan: Wrote</pre>dsfsdfs</pre>
在发布到服务器之前,会在客户端将其删除。我怎么能允许这个标签?
我也尝试过使用span class =“myClass”,这次删除了类标记
我的设置是
背后的代码
htmlEditorExtender1.EnableSanitization = true;
前码
<ajaxToolkit:HtmlEditorExtender ID="htmlEditorExtender1" TargetControlID="txtMessageBody"
runat="server" DisplaySourceTab="True">
<Toolbar>
<ajaxToolkit:Undo />
<ajaxToolkit:Redo />
<ajaxToolkit:Bold />
<ajaxToolkit:Italic />
<ajaxToolkit:Underline />
<ajaxToolkit:StrikeThrough />
<ajaxToolkit:Subscript />
<ajaxToolkit:Superscript />
<ajaxToolkit:JustifyLeft />
<ajaxToolkit:JustifyCenter />
<ajaxToolkit:JustifyRight />
<ajaxToolkit:JustifyFull />
<ajaxToolkit:InsertOrderedList />
<ajaxToolkit:InsertUnorderedList />
<ajaxToolkit:CreateLink />
<ajaxToolkit:UnLink />
<ajaxToolkit:RemoveFormat />
<ajaxToolkit:SelectAll />
<ajaxToolkit:UnSelect />
<ajaxToolkit:Delete />
<ajaxToolkit:Cut />
<ajaxToolkit:Copy />
<ajaxToolkit:Paste />
<ajaxToolkit:BackgroundColorSelector />
<ajaxToolkit:ForeColorSelector />
<ajaxToolkit:FontNameSelector />
<ajaxToolkit:FontSizeSelector />
<ajaxToolkit:Indent />
<ajaxToolkit:Outdent />
<ajaxToolkit:InsertHorizontalRule />
<ajaxToolkit:HorizontalSeparator />
</Toolbar>
</ajaxToolkit:HtmlEditorExtender>
和网络配置
<ajaxControlToolkit useStaticResources="true" renderStyleLinks="false" htmlSanitizer="AjaxControlToolkit.HtmlEditor.Sanitizer.DefaultHtmlSanitizer, AjaxControlToolkit.HtmlEditor.Sanitizer" />
当Yuriy的回答尝试时,它给出的完整错误
Value cannot be null.
Parameter name: type
Stack:
at System.Activator.CreateInstance(Type type, Boolean nonPublic)
at System.Activator.CreateInstance(Type type)
at AjaxControlToolkit.HtmlEditorExtender.CreateSanitizer()
at System.Lazy`1.CreateValue()
at System.Lazy`1.LazyInitValue()
at System.Lazy`1.get_Value()
at AjaxControlToolkit.HtmlEditorExtender.get_Sanitizer()
at AjaxControlToolkit.HtmlEditorExtender.OnInit(EventArgs e)
at System.Web.UI.Control.InitRecursive(Control namingContainer)
at System.Web.UI.Control.InitRecursive(Control namingContainer)
at System.Web.UI.Control.InitRecursive(Control namingContainer)
at System.Web.UI.Control.InitRecursive(Control namingContainer)
at System.Web.UI.Control.InitRecursive(Control namingContainer)
at System.Web.UI.Control.InitRecursive(Control namingContainer)
at System.Web.UI.Control.InitRecursive(Control namingContainer)
at System.Web.UI.Control.InitRecursive(Control namingContainer)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
类实现
答案 0 :(得分:1)
我认为最简单的方法是创建自己的IHtmlSanitizer
继承DefaultHtmlSanitizer
的实现,并覆盖GetSafeHtmlFragment
方法,如下所示
public class MyHtmlSanitizer : DefaultHtmlSanitizer, IHtmlSanitizer
{
private static readonly string[] whiteListTags = (ConfigurationManager.AppSettings["whiteListTags"] ?? "").Split(',');
string IHtmlSanitizer.GetSafeHtmlFragment(string htmlFragment, Dictionary<string, string[]> whiteList)
{
foreach (var tag in whiteListTags)
{
if (!whiteList.ContainsKey(tag))
whiteList.Add(tag, new string[0]);
}
return base.GetSafeHtmlFragment(htmlFragment, whiteList);
}
}
然后添加到自己的标签白名单的web.config设置的appSettings部分:
<appSettings>
<add key="whiteListTags" value="pre"/>
</appSettings>
并配置工具包以使用此清洁剂而不是默认值:
<ajaxControlToolkit
useStaticResources="true"
renderStyleLinks="false"
htmlSanitizer="AjaxControlToolkit.Customization.MyHtmlSanitizer, AjaxControlToolkit.Customization"
tempFolder="~/Temp"/>