将字符串动态分配给文本框会导致错误"A potentially dangerous Request.Form value was detected from the client"



我有一个ASP.NET web表单,允许用户从我的应用程序内部发送电子邮件。该表单包含三个文本框、一个文件上载控件和一个用于发送电子邮件的按钮。

Mailmessage.value=;

当我注释掉上面的行并将其替换为"Mailmessage.Value = "Some string";"时,我的程序运行良好。

以上内容包含在名为"EmailButton_click"的单击事件处理程序中。我已经尝试了下面文章中列出的所有解决方案,但没有一个解决了我的问题:http://www.aspsnippets.com/Articles/ASPNet-Error-A-potentially-dangerous-RequestForm-value-was-detected-from-the-client.aspx

提前感谢您的帮助。

在调用该方法的aspx页面中将validate请求设置为false。

ValidateRequest = "false"

并像这个一样构建你的消息

 StringBuilder msg =  new StringBuilder();
 msg.Append(Environment.NewLine);
 msg.Append(Environment.NewLine);
 msg.Append(Environment.NewLine);
 msg.Append("Issue ID: ");
 msg.Append(Session["IssueID"].ToString());
 msg.Append(Environment.NewLine);
 msg.Append("Issue Name: ");
 msg.Append(Session["IssueName"].ToString());
 msg.Append(Environment.NewLine);
 msg.Append(Environment.NewLine);
 msg.Append("Please do not reply to this message. Replies to this message are routed to an unmonitored mailbox. If you have questions or comments, please contact ");
 msg.Append(Session["UserFullName"].ToString());
 msg.Append(" at "");
 msg.Append(Session["UserEmailAddress"].ToString());
 msg.Append("CONFIDENTIALITY NOTICE: This communication with its contents may contain confidential and/or legally privileged information. It is solely for the use of the intended recipient(s). Unauthorized interception, review, use, forwarding or disclosure is prohibited and may violate applicable laws including the Electronic Communications Privacy Act. If you are not the intended recipient, please contact the sender and destroy all copies of the communication.");
 Mailmessage.Value = msg.ToString();  

最新更新