The remote server returned an error: (403) Forbidden.
-
Good Day Everyone I have a response which i convert to byte array and download the pdf at the end. This code does download a PDF in localhost but gives an error {"Thread was being aborted."} and the file still get downloaded correctly. The code is defined as below
string URL = "http://myserver/ReportServer/Pages/ReportViewer.aspx?%2Fbills%2FISU\_PDF\_GEN\_APT&rs:Command=Render";
string Command = "Render";
string Format = "PDF";
//We can get values of these parameters from Request object.
string Contract_account_number = AccountNumber;
URL = URL + "&rs:Command=" + Command + "&rs:Format=" + Format + "&Contract_Account_Number=" + Contract_account_number;
System.Net.HttpWebRequest Req = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(URL);
Req.Credentials = System.Net.CredentialCache.DefaultCredentials;
Req.UseDefaultCredentials = true;
Req.Method = "GET";
System.Net.WebResponse objResponse = Req.GetResponse();
System.IO.Stream stream = objResponse.GetResponseStream();
var document = GenericMethods.StreamToByteArray(stream);
Response.AddHeader("Content-type", "application/octet-stream");
Response.AddHeader("Content-Disposition", "attachment; filename=" + AccountNumber + ".pdf");
Response.BinaryWrite(document);
Response.Flush();
Response.End();when i host this in IIS i get an Error The remote server returned an error: (403) Forbidden. Thanks
Vuyiswa Maseko, Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code. C#/VB.NET/ASP.NET/SQL7/2000/2005/2008 http://www.vimalsoft.com vuyiswa[at]vimalsoft.com
-
Good Day Everyone I have a response which i convert to byte array and download the pdf at the end. This code does download a PDF in localhost but gives an error {"Thread was being aborted."} and the file still get downloaded correctly. The code is defined as below
string URL = "http://myserver/ReportServer/Pages/ReportViewer.aspx?%2Fbills%2FISU\_PDF\_GEN\_APT&rs:Command=Render";
string Command = "Render";
string Format = "PDF";
//We can get values of these parameters from Request object.
string Contract_account_number = AccountNumber;
URL = URL + "&rs:Command=" + Command + "&rs:Format=" + Format + "&Contract_Account_Number=" + Contract_account_number;
System.Net.HttpWebRequest Req = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(URL);
Req.Credentials = System.Net.CredentialCache.DefaultCredentials;
Req.UseDefaultCredentials = true;
Req.Method = "GET";
System.Net.WebResponse objResponse = Req.GetResponse();
System.IO.Stream stream = objResponse.GetResponseStream();
var document = GenericMethods.StreamToByteArray(stream);
Response.AddHeader("Content-type", "application/octet-stream");
Response.AddHeader("Content-Disposition", "attachment; filename=" + AccountNumber + ".pdf");
Response.BinaryWrite(document);
Response.Flush();
Response.End();when i host this in IIS i get an Error The remote server returned an error: (403) Forbidden. Thanks
Vuyiswa Maseko, Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code. C#/VB.NET/ASP.NET/SQL7/2000/2005/2008 http://www.vimalsoft.com vuyiswa[at]vimalsoft.com
The
ThreadAbortException
is expected when you callResponse.End
: ThreadAbortException occurs if you use Response.End - ASP.NET | Microsoft Docs[^] The error in IIS simply means that the user your application pool is running as doesn't have access to the resource you're trying to load. It works when you debug the code in Visual Studio because it's running under your user account at that point. Change the SSRS permissions to give your App Pool user access to run the reports; change your App Pool to run as a user with the relevant permissions; or change your code to pass the credentials of a user with the relevant permissions instead of relying on the default credentials.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer