输入框中含有Html标签时页面报错,该如何解决

2025-04-23 21:26:21
推荐回答(1个)
回答1:

当输入框中含有Html标签时页面报错,跟踪发现是“从客户端(。。。)中
检测到有潜在危险的 Request.Form 值
”异常,但设置“ValidateRequest=false”后没有效果,发现还是弹出错误提示,且提示为“Sys.WebForms.PageRequestManagerServerErrorException: 在服务器上处理请求时出现未知错误。服务器返回的状态码为: 500 ”。
当前页面为母版页的内容页,且页面中含有updatepanel。
如果设置Page_Error事件,如果调用Response.Write或ScriptManager.RegisterStartupScript弹出提示的话,页面也会弹出同样错误提示,代码如下:
protected void Page_Error(object sender, EventArgs e){Exception ex = HttpContext.Current.Server.GetLastError();
if (ex is HttpRequestValidationException){//ScriptManager.RegisterStartupScript(UpdatePanel1, typeof(UpdatePanel), msg, alert('请输入合法的字符串!');, true);
//HttpContext.Current.Response.Write(------解决方案--------------------------------------------------------
------解决方案--------------------------------------------------------
要替换掉<,
------解决方案--------------------------------------------------------
不用替换 转义即可.
例如 把 < 转义成 < 等等
------解决方案--------------------------------------------------------