Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. The remote server returned an error: (403) Forbidden.

The remote server returned an error: (403) Forbidden.

Scheduled Pinned Locked Moved ASP.NET
csharpasp-netcomsysadmin
2 Posts 2 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    Vimalsoft Pty Ltd
    wrote on last edited by
    #1

    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

    Richard DeemingR 1 Reply Last reply
    0
    • V Vimalsoft Pty Ltd

      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

      Richard DeemingR Offline
      Richard DeemingR Offline
      Richard Deeming
      wrote on last edited by
      #2

      The ThreadAbortException is expected when you call Response.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

      "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups