PDF生成在IIS上获取错误

时间:2016-08-16 04:09:30

标签: c# asp.net pdf-generation

这个相同的代码在我的本地机器上工作,因为我通过VS2015 IDE运行此代码但是当我将它发布到IIS时出现以下错误:

  '/'应用程序中的服务器错误。远程服务器返回错误:   (404)未找到。描述:发生了未处理的异常   在执行当前Web请求期间。请查看   堆栈跟踪以获取有关错误及其位置的更多信息   起源于代码。异常详细信息:System.Net.WebException:   远程服务器返回错误:(404)Not Found。来源错误:
  在执行期间生成了未处理的异常   当前的网络请求。有关的来源和位置的信息   可以使用下面的异常堆栈跟踪来识别异常。   堆栈跟踪:[WebException:远程服务器返回错误:   (404)Not Found。] System.Net.HttpWebRequest.GetResponse()+8420880   iTextSharp.text.Image.GetInstance(Uri url)+109
  iTextSharp.text.html.simpleparser.ElementFactory.CreateImage(字符串   src,IDictionary 2 attrs, ChainedProperties chain, IDocListener document, IImageProvider img_provider, Dictionary 2 img_store,String   img_baseurl)+388
  iTextSharp.text.html.simpleparser.HTMLWorker.CreateImage(IDictionary 2 attrs) +448
iTextSharp.text.html.simpleparser.HTMLTagProcessor_IMG.StartElement(HTMLWorker worker, String tag, IDictionary
2 attrs)+113
  iTextSharp.text.html.simpleparser.HTMLWorker.StartElement(String tag,   IDictionary`2 attrs)+127
  iTextSharp.text.xml.simpleparser.SimpleXMLParser.Go(TextReader reader)   +1334 Therasmart.admin.InvoicePdf.Page_Load(Object sender,EventArgs e)+675 System.Web.UI.Control.LoadRecursive()+71
  System.Web.UI.Page.ProcessRequestMain(布尔   includeStagesBeforeAsyncPoint,Boolean includeStagesAfterAsyncPoint)   3178

我的代码如下:

protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (GetTherepistDetails() == "success" && GetInvoice() == "success" && GetClientDetails() == "success")
                {

                    Response.ContentType = "application/pdf";
                    Response.AddHeader("content-disposition", "attachment;filename=Invoice.pdf");
                    Response.Cache.SetCacheability(HttpCacheability.NoCache);

                    var sw = new StringWriter();
                    var hw = new HtmlTextWriter(sw);
                    this.Page.RenderControl(hw);
                    var sr = new StringReader(sw.ToString());
                    var pdfDoc = new Document();
                    pdfDoc.SetPageSize(PageSize.A4);
                    var htmlparser = new HTMLWorker(pdfDoc);
                    PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
                    pdfDoc.Open();

                    ServicePointManager.ServerCertificateValidationCallback = delegate (object s, System.Security.Cryptography.X509Certificates.X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; };

                    htmlparser.Parse(sr);
                    pdfDoc.Close();
                    Response.Write(pdfDoc);
                    Response.End();
                }
                else
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "redirect", "alert('Getting error in Invoice generation copy has been sent.');", true);
                }
            }
        }

请帮忙解决此问题。

0 个答案:

没有答案