Click here to Skip to main content
15,886,782 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
if i onclick of a button(btnConverttoPDF) in some form 
itwill create pdf with all the content inside the form..
it's working fine locally..

But when the application is deployed in server then 
it's raising an error.. as follows



"No connection could be made because the target machine actively refused it 127.0.0.15:55374"

WebException: unable to connect to the remove server

and mentioning the path of the file like
E:\Main\OnlineSite\OnlineBanking\ClosingBalance.aspx.cs


What i noticed here is 127.0.0.15 is my IP and 55374 is my portno where i developed the app

ASP.NET
I found the issue.. 

<asp:Image ID="Image1" ImageUrl="http://localhost:55374/img/bank_logo.png" runat="server">

the above control is causing an issue.. during 
htmlparser.Parse(sr);

May i know How can i resolve it?


What I have tried:

protected void btnconvert_Click(object sender, EventArgs e)
{
using (StringWriter sw = new StringWriter())
{
using (HtmlTextWriter hw = new HtmlTextWriter(sw))
{
//To Export all pages
grdLast10trans.AllowPaging = false;
//Calling a Function, here im adding the data to the Datasource and diplaying in Grid
BindGrid();
content.RenderControl(hw);
StringReader sr = new StringReader(sw.ToString());
Document pdfDoc = new Document(PageSize.A3, 10f, 10f, 10f, 10f);
HTMLWorker htmlparser = new HTMLWorker(pdfDoc);

PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
pdfDoc.Open();
//pdfDoc.NewPage();
htmlparser.Parse(sr); //Error Occurring here
pdfDoc.Close();
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=GridViewExport.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Write(pdfDoc);
HttpContext.Current.ApplicationInstance.CompleteRequest();
}
}
}
Posted
Updated 16-Feb-16 2:18am
v9
Comments
F-ES Sitecore 16-Feb-16 7:07am    
You'll be hard-coding the url 127.0.0.15:55374 somewhere in your code, you need to find out where and change that code such that it either doesn't need the whole url including domain, or if it does it uses the current domain rather than a hard-coded one.

1 solution

http://localhost:55374/img/bank_logo.png is a absolute URL, with a logical glitch...localhost refers always the machine on which the site hosted...
To resolve it use relative URL like /img/bank_logo.png, which is relative to the root (/) of your site and should work from every host...

(As for your specific problem...on the development machine you are using IIS Express - or Cassini for older VS - and it will choose the port dynamically from the higher range of available ports. On a normal host you will use the standard 80 - 443 - port for HTTP, and specifying the port will lead to error...)
 
Share this answer
 
Comments
JanardhanSharma 16-Feb-16 9:02am    
Thanq, I tried by making ImageUrl="\img\bank_logo.PNG" But still it's giving an error as below

Could not find a part of the path 'c:\img\bank_logo.PNG'.
JanardhanSharma 16-Feb-16 9:10am    
Just now i tried.. The following path resolved the issue
http://localhost/Online/img/bank_logo.PNG

Than q

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900