Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#3.0 ASP.NET
In my asp page i write this code for sending mail
 
protected void Btn_SendMail_Click(object sender, EventArgs e)
    {
 
        MailMessage mail = new MailMessage();
        mail.To.Add(txtTo.Text);
        //mail.To.Add("Another Email ID where you wanna send same email");
        mail.From = new MailAddress("abc@xxx.com");
        mail.Subject = txtSubject.Text;
        mail.Body = txtBody.Text;
        mail.IsBodyHtml = true;
        SmtpClient smtp = new SmtpClient();
        smtp.Host = "smtp.gmail.com"; //Or Your SMTP Server Address
        smtp.Credentials = new System.Net.NetworkCredential("abc@xxx.com", "abcd123");
        smtp.EnableSsl = true;
        smtp.Send(mail);
        Label1.Text = "Sent Successfully...";
        clear();
txtBody.text="
<html>
<head>
<title>Test </title>
</head>
<body>
<table>
<tr>
<td> USERName: </td>
<td>Password </td>
</tr>
</table>
</body>
</html>
"

But i got this error "
A potentially dangerous Request.Form value was detected from the client (txtBody="<html>
<head>
<tit...").
Description: Request Validation has detected a potentially dangerous client input value, and processing of the request has been aborted. This value may indicate an attempt to compromise the security of your application, such as a cross-site scripting attack. You can disable request validation by setting validateRequest=false in the Page directive or in the configuration section. However, it is strongly recommended that your application explicitly check all inputs in this case.
 
Exception Details: System.Web.HttpRequestValidationException: A potentially dangerous Request.Form value was detected from the client (txtBody="<html>
<head>
<tit...").
"

 
please some one help me......!
Posted 14-Dec-12 1:56am
Comments
FehPorto at 14-Dec-12 7:05am
   
you got to send a test email? Without taking the html, just the same text
example: Mail.Body = "This email was sent."

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

The error is caused by having html in your text box.
 
In the page directivesin the ASPX page add the following
validateRequest="false"
 
For .Net 4.0 you may also need to make a change in your web config
<httpruntime requestvalidationmode="2.0" />
 
Have a look here too
http://msdn.microsoft.com/en-us/library/system.web.httprequestvalidationexception.aspx[^]
  Permalink  
Comments
Pyledriver at 9-Jan-13 3:01am
   
Did this answer your question? If so please mark as answer. Thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 584
1 Maciej Los 275
2 DamithSL 233
3 Sergey Alexandrovich Kryukov 209
4 BillWoodruff 200
0 OriginalGriff 6,803
1 Sergey Alexandrovich Kryukov 6,377
2 DamithSL 5,421
3 Manas Bhardwaj 4,841
4 Maciej Los 4,330


Advertise | Privacy | Mobile
Web03 | 2.8.1411023.1 | Last Updated 14 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100