, ASP.NET 4 ValidateRequest @Page <httpRuntime requestValidationMode="2.0" /> web.config. . :
http://www.asp.net/whitepapers/aspnet4/breaking-changes
:
namespace Controls
{
public class HtmlTextBox : TextBox
{
protected override bool LoadPostData(string postDataKey, System.Collections.Specialized.NameValueCollection postCollection)
{
bool res = base.LoadPostData(postDataKey, postCollection);
Text = Text.Replace("<", "<").Replace(">", ">").Replace("&", "&");
return res;
}
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
ScriptManager.RegisterOnSubmitStatement(this, this.GetType(), "htmlTextBox" + UniqueID, "try { var item = document.getElementsByName('" + UniqueID + "')[0]; item.value = item.value.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>'); } catch (err) {}");
}
}
}
web.config:
<system.web>
<pages>
<controls>
<add tagPrefix="uc1" namespace="Controls" />
</controls>
</pages>
</system.web>
That way you can just use <uc1:HtmlTextBox runat="server" />it if you want the text box to host html, but other controls on the page will still be blocked from posting html, unlike the approach where you disable ValidateRequest.
source
share