我从asp网页发送邮件时遇到了另一个问题 [英] i get another problem in sending mail from my asp web page

查看:64
本文介绍了我从asp网页发送邮件时遇到了另一个问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的asp页面中,我写了这封发送邮件的代码



  protected   void  Btn_SendMail_Click( object  sender,EventArgs e)
{

MailMessage mail = new MailMessage();
mail.To.Add(txtTo.Text);
// mail.To.Add(您要发送同一封电子邮件的另一个电子邮件ID);
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; // 或您的SMTP服务器地址
smtp.Credentials = new System.Net.NetworkCredential( abc@xxx.com abcd123);
smtp.EnableSsl = true ;
smtp.Send(mail);
Label1.Text = 已成功发送...;
clear();



txtBody.text =

 < ;   html  >  
< head >
< title > 测试< ; / title >
< / head >
< 正文 >
< 表格 >
< tr >
< td > USERName:< < span class =code-leadattribute> / td >
< td > 密码< < span class =code-leadattribute> / td >
< / tr >
< / table >
< ; / body >
< ; / html >





但我收到此错误

从客户端检测到一个潜在危险的Request.Form值(txtBody =<   html  >  
< span class =code-keyword>< head >
< tit ...)。

描述: 请求 验证 检测到 a 可能 危险 client 输入 value, processing > request < span class =code-attribute> 已中止。 value 可能 表示 < span class =code-attribute> 尝试 to 妥协 security 您的 application, as a 跨站点 脚本 attack。 禁用 request validation by 设置 validateRequest = false Page < span class =code-attribute> 指令 configuration se ction。 但是, it strong 推荐 您的 application 显式 检查 所有 输入 case。



异常 详细信息: System.Web.HttpRequestValidationException: A 可能 危险 Request.Form value 检测到 来自 client (txtBody = < HTML>
< head>
< tit ...
)。









请有人帮助我......!

解决方案

错误是由文本框中包含html引起的。



在ASPX页面的页面指令中添加以下内容

 validateRequest =false





对于.Net 4.0,您可能还需要对您的网络配置进行更改

< httpruntime requestvalidationmode =2.0/> 





看看这里

http://msdn.microsoft.com/en-us/library/system.web.httprequestvalidationexception.aspx [ ^ ]


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......!

解决方案

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[^]


这篇关于我从asp网页发送邮件时遇到了另一个问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆