Webform1.aspx
has grid.Grid contains edit button。点击编辑按钮,用户被重定向到webform2.aspx
页面。查询字符串ID传递给Webform2.aspx
。 Webform2.aspx
显示该ID的所有数据。 Webform包含下拉列表,文本框和按钮等。从客户端检测到潜在危险的Request.Form值
我从数据库中提取记录并将其分配给像下拉列表,文本框和按钮之类的控件。将值分配给包含<
或>
的文本框并尝试更新记录时。它引发一个异常。例外是A potentially dangerous Request.Form value was detected from the client
。所以我尝试使用htmlencode方法。
下面是我的代码 在CS文件
public partial class Webform1 : System.Web.UI.Page
{
string strUrl="";
protected void Page_Load(object sender, EventArgs e)
{
// Fetching value from database and assigning to string
Textbox1.Text= dr["URL"].ToString();
// directly use string
//strUrl= dr["URL"].ToString();
}
protected void button_Click(object sender, EventArgs e)
{
string s2 ="";
string s3 = "";
strUrl= Textbox1.Text;
if ((strUrl.Contains("<")) || (strUrl.Contains(">")))
{
s2 = Server.HtmlEncode("<");
s3 = Server.HtmlEncode(">");
strUrl= strPingUrl.Replace("<", s2);
strUrl= strPingUrl.Replace(">", s3);
}
Textbox1.Text =strUrl;
// updation code
当我将尝试插入它抛出分配值的TextBox如果我使用string.It工作的exception.Instead。我可以更新记录。但我不想这样。用户可以更改文本框中的值。所以我想从文本框中获取价值。
你检查吗? http://stackoverflow.com/questions/81991/a-potentially-dangerous-request-form-value-was-detected-from-the-client?rq=1 – Ravimallya 2015-03-25 05:34:12
是的,我访问该页面。我不想使用这段代码。 <的httpRuntime requestValidationMode = “2.0”/> <结构> <页validateRequest = “假”/> 配置> –
2015-03-25 05:39:00
尝试http://www.codeproject.com/Tips/423413/Submit -HTML-Text-with-Page-Validation-On-On-On – Amit 2015-03-25 06:13:12