0

I have an ASP.NET web form that allows a user to send an e-mail from inside my application. The form contains three text boxes, a file upload control, and a button for sending the e-mail.

Mailmessage.value = ;

When I comment out the above line and replace it with "Mailmessage.Value = "Some string";", my program works fine.

The above is contained inside of a click event handler named "EmailButton_Click". I've tried all of the solutions outlined in the following article, but none of them solved my problem: http://www.aspsnippets.com/Articles/ASPNet-Error-A-potentially-dangerous-RequestForm-value-was-detected-from-the-client.aspx

Thanks in advance for your help.

Techie2015
  • 47
  • 1
  • 10
  • Use a stringbuilder to construct the message. – VK_217 May 10 '16 at 21:04
  • 3
    Possible duplicate of [A potentially dangerous Request.Form value was detected from the client](http://stackoverflow.com/questions/81991/a-potentially-dangerous-request-form-value-was-detected-from-the-client) – Xiaoy312 May 10 '16 at 21:14
  • What is **Mailmessage.Value**? I don't think Mailmessage.Value line throws exception. Could you debug line-by-line, and post the line that throws the exception? – Win May 10 '16 at 21:50

1 Answers1

0

Set the validate request to false in the aspx page you are calling the method.

ValidateRequest = "false"

and construct your message like this

 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();  
VK_217
  • 9,965
  • 7
  • 34
  • 52
  • I tried your solution, but I contiinue to get the same error. I also tried setting the page directive ValidateRequest to false. – Techie2015 May 10 '16 at 21:21