我必須發送郵件附件。我的代碼只適用於文件小於4MB。 我已經檢查了網上的所有內容,但是所有人都建議使用相同的soolution。即在webconfig中更改我已經完成的httpruntime屬性。無法上傳文件大於4 MB使用文件上傳在asp.net 3.5
<httpRuntime maxRequestLength="10000" executionTimeout="1500" />
我已經改變了在網絡「超時」屬性config.Also保持活動的應用程序配置做了更改IIS,但即使這樣做後,這一切都改變了問題依然留在我application.everytime我嘗試一切在1.5分鐘後上傳大於4mb的連接超時文件。
在點擊事件
protected void btnSend_Click(object sender, EventArgs e)
{
MailMessage msg = new MailMessage();
SmtpClient smtp = new SmtpClient();
string strFrom = txtFrom.Text;
string strTo = txtTo.Text;
string strSubject= ddlTemplate.SelectedItem.Text.ToString();
string strBody =txtBody.Text;
string strCC =txtCC.Text;
string strBCC =txtBCC.Text;
if (this.fuAttachments.HasFile)
{
Attachment at = new Attachment(fuAttachments.PostedFile.InputStream,fuAttachments.PostedFile.ContentType);
at.ContentDisposition.FileName = this.fuAttachments.FileName;
msg.Attachments.Add(at);
}
smtp.EnableSsl = true;
msg.From = new MailAddress(strFrom);
msg.To.Add(strTo);
msg.Subject = strSubject;
msg.Body = strBody;
//smtp = new SmtpClient("localhost");
//smtp.UseDefaultCredentials = true;
try
{
smtp.Send(msg);
}
catch (SmtpException Ex)
{
throw;
}
if (msg.Attachments.Count > 0)
{
//Clear the attachments and delete the sessionid folder from tempFiles
msg.Attachments.Dispose();
}
}
您是否增加了執行超時? as 1500ms is 1.5sec – 2012-04-24 10:15:14
that's 1500 seconds not ms .... see [this](http://msdn.microsoft.com/en-us/library/e1f13641.aspx) – vatsal 2012-04-24 10:27:03
噢謝謝我糾正 – 2012-04-24 10:36:11