我们在一个ASP.Net ASP.Net项目中使用Telerik Rad Controls for MVC Ajax。RadChart生成以下超文本标记语言:
<img onerror="if(confirm('Error loading RadChart image.\nYou may also wish to check the ASP.NET Trace for further details.\nDisplay stack trace?'))window.location.href=this.src;" src="ChartImage.axd?UseSession=true&ChartID=e25ad666-e05b-4a92-ac0c-4f2c729b9382_chart_ctl00$MainContent$AverageCTMChart&imageFormat=Png&random=0.501658702968461" usemap="#imctl00_MainContent_AverageCTMChart" style="border-width: 0px;" alt="">我想删除onerror属性;我真的不想让客户在出现问题时看到堆栈跟踪。我看不到任何方法来控制这个控件生成的标记。谷歌搜索没有提供任何帮助。以前有没有人处理过这个问题?
如何删除onerror属性?
发布于 2010-06-25 22:33:56
onerror仅在调试配置中显示。一旦你在Release中部署了你的应用程序,这个属性就不会被渲染!
发布于 2010-04-15 21:56:01
您可以这样做,只需将其添加到页面底部或在某个load事件中调用removeOnError。
function removeOnError(){
//Grab all images
var imgs = document.getElementsByTagName('img');
for(var i=0;i<imgs.length;i++){
//If they've got the onerror attribute
if(imgs[i].onerror){
//set it to null
imgs[i].onerror = null;
}
}
}
//Call the function above
removeOnError();编辑
看一下Telerik的网站,它似乎不是一个选项,所以我能想到的唯一方法就是覆盖页面的Render事件,并手动将其删除:
protected override void Render(HtmlTextWriter writer)
{
using (System.IO.MemoryStream MS = new System.IO.MemoryStream())
{
using (System.IO.StreamWriter SW = new System.IO.StreamWriter(MS))
{
HtmlTextWriter NW = new HtmlTextWriter(SW);
base.Render(NW);
NW.Flush();
MS.Position = 0;
using (System.IO.StreamReader SR = new System.IO.StreamReader(MS))
{
string html = SR.ReadToEnd();
MatchCollection MC = Regex.Matches(html, "<img.*?(?<OnError>onerror=\".*?\").*?>");
foreach (Match M in MC)
{
if (M.Success)
{
html = html.Replace(M.Groups["OnError"].Value, "");
}
}
Response.Write(html);
SR.Close();
}
}
}
} 发布于 2013-12-24 20:55:57
Telerik控件检查属性
HttpContext.Current.IsDebuggingEnabled决定是否生成onError属性。因此,要删除这些块,请确保在web.config的“compilation”节点中关闭了调试
<compilation debug="false"> https://stackoverflow.com/questions/2645567
复制相似问题