---
title: "从客户端检测到有潜在危险的Request.Form 值。原因及其解决方法"
author: "Andy_Dou"
date: "2009-03-09T22:22:19Z"
tags: []
slug: "request-form"
draft: false
lastmod: "2009-03-09T22:28:21Z"
id: 346173
url: "https://ideabean.iteye.com/blog/346173"
---

原因：页面请求（request）时，含有html或javascript等字符串时。ASP.NET会认为是危险的值，就会抛出辞异常。当页面上使用了所见即所得编辑器（例如使用了fckeditor或FreeTextBox控件等）的时候会发生此异常。

解决方法一：在页面上加入 &lt;% Page ValidateRequest="false"  %&gt;

解决方法二：修改Web.Config配置文件的&lt;pages&gt;标签。&lt;pages validateRequest="false"&gt;...&lt;/pages&gt;。这个方法会将所有的页面校验功能去掉，所以不推荐使用此方法。

 

解决方法三：捕获异常，这样你就可以自己来定义异常的提示方式。

 

 protected void Page\_Error(object sender, EventArgs e)  
    {  
        Exception ex = Server.GetLastError();  
        if (HttpContext.Current.Server.GetLastError() is HttpRequestValidationException)  
        {  
            HttpContext.Current.Response.Write("这里输入需要提示的异常信息");  
            HttpContext.Current.ClearError();  
        }  
    }