Я пытаюсь создать приложение, которое преобразует HTML в PDF-документ, а затем отправляет его по электронной почте в виде вложения.
Я получаю эту ошибку The underlying connection was closed: The connection was closed unexpectedly.
Пробовал Googling, но не повезло;какие-либо подсказки, почему это могло произойти?
Редактировать: Ошибка возникает в строке 28: html2pdf.Run(Convert);
<%@ Import Namespace="System.Web.Mail" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="Pdfizer" %>
<script language="c#" runat="server">
protected override void OnLoad(EventArgs e)
{
sendApplication();
}
private void sendApplication()
{
string template = "X:\\path\\to\\file\\temp.htm"; //HTML Form to send
Stream steam = new FileStream("X:\\path\\to\\file\\app.pdf", FileMode.Create, FileAccess.Write, FileShare.Write); //Stream to write to file.
string fileToSend = "X:\\path\\to\\file\\app.pdf"; //PDF to send(after creation)
string smtpServer = "spamfilter1.com";
string sendFrom = "test@test.com";
string sendTo = "test@test.com";
//Read template
StreamReader templateFile = new StreamReader(template);
string Convert = templateFile.ReadToEnd();
templateFile.Close();
//Convert to PDF
HtmlToPdfConverter html2pdf = new HtmlToPdfConverter();
html2pdf.Open(steam);
html2pdf.AddChapter(@"_");
html2pdf.Run(Convert);
html2pdf.Close();
//Send email and attachment
MailMessage msg = new MailMessage();
msg.To = sendTo;
msg.From = sendFrom;
msg.Subject = "New Application";
msg.Body = Convert;
MailAttachment attach = new MailAttachment(fileToSend);
msg.Attachments.Add(attach);
SmtpMail.SmtpServer = smtpServer;
SmtpMail.Send(msg);
lblStatus.Text = "Application Submitted.";
}
</script>
Вот вся трассировка
Server Error in '/WebSite1' Application.
The underlying connection was closed: The connection was closed unexpectedly.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Net.WebException: The underlying connection was closed: The connection was closed unexpectedly.
Source Error:
Line 26: html2pdf.Open(steam);
Line 27: html2pdf.AddChapter(@"_");
Line 28: html2pdf.Run(Convert);
Line 29: html2pdf.Close();
Line 30:
Source File: c:\Users\Jeff\Documents\Visual Studio 2010\WebSites\WebSite1\sstnS.aspx Line: 28
Stack Trace:
[WebException: The underlying connection was closed: The connection was closed unexpectedly.]
System.Net.HttpWebRequest.GetResponse() +6111059
System.Xml.XmlDownloadManager.GetNonFileStream(Uri uri, ICredentials credentials, IWebProxy proxy, RequestCachePolicy cachePolicy) +107
System.Xml.XmlDownloadManager.GetStream(Uri uri, ICredentials credentials, IWebProxy proxy, RequestCachePolicy cachePolicy) +4012381
System.Xml.XmlUrlResolver.GetEntity(Uri absoluteUri, String role, Type ofObjectToReturn) +69
System.Xml.XmlTextReaderImpl.OpenAndPush(Uri uri) +171
System.Xml.XmlTextReaderImpl.PushExternalEntityOrSubset(String publicId, String systemId, String baseUriStr, Uri& baseUri, String entityName) +252
System.Xml.XmlTextReaderImpl.DtdParserProxy_PushExternalSubset(String systemId, String publicId) +46
System.Xml.DtdParserProxy.System.Xml.IDtdParserAdapter.PushExternalSubset(String systemId, String publicId) +16
System.Xml.DtdParser.ParseExternalSubset() +21
System.Xml.DtdParser.ParseInDocumentDtd(Boolean saveInternalSubset) +4133593
System.Xml.DtdParser.Parse(Boolean saveInternalSubset) +54
System.Xml.DtdParser.System.Xml.IDtdParser.ParseInternalDtd(IDtdParserAdapter adapter, Boolean saveInternalSubset) +31
System.Xml.XmlTextReaderImpl.ParseDtd() +72
System.Xml.XmlTextReaderImpl.ParseDoctypeDecl() +219
System.Xml.XmlTextReaderImpl.ParseDocumentContent() +453
System.Xml.XmlTextReaderImpl.Read() +145
System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace) +114
System.Xml.XmlDocument.Load(XmlReader reader) +114
System.Xml.XmlDocument.LoadXml(String xml) +168
Pdfizer.HtmlToPdfConverter.Run(String html) +134
ASP.sstns_aspx.sendApplication() in c:\Users\Jeff\Documents\Visual Studio 2010\WebSites\WebSite1\sstnS.aspx:28
ASP.sstns_aspx.OnLoad(EventArgs e) in c:\Users\Jeff\Documents\Visual Studio 2010\WebSites\WebSite1\sstnS.aspx:9
System.Web.UI.Control.LoadRecursive() +74
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2207
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1
Я также должен сказать, что отправка и вложение электронной почты работает должным образом (уже проверено).