当输入框中含有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("<script>alert('请输入合法的字符串!');</script>");
        HttpContext.Current.Server.ClearError();
    }
}
请问如何解决,谢谢

解决方案 »

  1.   

    是一些Html标签,如<html><table><td>之类的,输入框中有这些的话会报错
      

  2.   

    不用替换 转义即可.
    例如 把 < 转义成 &lt;  等等 
      

  3.   

    你用到了ajax的话,直接可以 encodeURI()
      

  4.   

    <httpRuntime requestValidationMode="2.0" />配置文件这样写
      

  5.   

    一定要设置ScriptManager控件的 EnablePartialRendering="False" ,要不然updatepanel内生成javascript回发方法的控件点击会出错