当我试着把这个放在这样的文本框里时,我遇到了一个错误,
tbGameTitle.Text = "<iframe id = 'ForIframe' src='http://e.gamesalad.com/play/117208' allowTransparency='true' scrolling='no'></iframe>";当我点击我的按钮
myThing.InnerHtml = tbGameTitle.Text;它会抛出这个错误
A potentially dangerous Request.Form value was detected from the client (tbGameTitle="<iframe id = 'ForIfr..."). 如果我在页面负载事件上有这个负载,那么就可以了。但是,当我在文本框中输入这个并单击我的按钮时,它就会抛出这个错误。我让它在另一个项目中工作很久以前,它从来没有抛出这个错误。
发布于 2014-02-26 19:46:59
当提交ASP.Net表单内容时,会检查它是否存在危险内容(比如之类的内容被标记为潜在的危险并被拒绝)。有几种方法可以允许提交这些内容,HTML在将文本发送到服务器之前对其进行编码,或者使用页面顶部的标记禁用请求验证(可能不安全!):
<@ Page validateRequest="false" %>有关请求验证的更多信息可以在此链接上找到。
发布于 2014-02-26 19:40:01
您需要转义像"<“这样的字符。阅读一些关于:XSS
这个帖子一定很有用。
您希望从该页面中获得的主要代码是:
// The event to escape the data and store in our HiddenField
jQuery('.allow_html textarea').blur(function () {
jQuery(jQuery(this).parent()).find('input[type="hidden"]').val(escape(jQuery(this).val()));
});
// The code to unescape the code and set it in our textbox
jQuery('.allow_html textarea').each(function(idx, item) {
var value = jQuery(jQuery(item).parent()).find('input[type="hidden"]').val();
jQuery(item).val(unescape(value));
});它将在输入中转义HTML代码。
而且,在服务器端,您需要解开它:
// encode the data
HtmlCodeHiddenField.Value = Uri.EscapeDataString(EscapedHtml);
// decode the data
string myHtml = Uri.UnescapeDataString(HtmlCodeHiddenField.Value);https://stackoverflow.com/questions/22051442
复制相似问题