1

I have the following code which I want to use to download an SSRS report as a PDF into a folder

Protected Sub BtnPDF_Click(sender As Object, e As EventArgs)
    Try
        Dim client As New WebClient()
        client.Headers.Add("user-agent", "Document download")
        client.UseDefaultCredentials = True
        'client.DownloadFile("http://server-name1/ReportServer_REPORTSDB/Pages/ReportViewer.aspx?%2fReport_Folder%2fReportName&rs:Command=Render&ID=12421&DTE=0&rs:Format=PDF", "\\server-name1\SharedFolder\Test2.pdf")
        'client.DownloadFile("http://server-name2/ReportServer_REPORTSDB/Pages/ReportViewer.aspx?%2fReport_Folder%2fReportName&rs:Command=Render&ID=12421&DTE=0&rs:Format=PDF", "\\server-name1\SharedFolder\Test2.pdf")
        'client.DownloadFile("http://server-name2/NormalWebsite/Documents/UserGuide.pdf", "\\server-name1\SharedFolder\Test2.pdf")
    Catch ex As Exception
        txtComments.Text = ex.Message
    End Try
End Sub

Note the lines commented out: When running the code in Visual Studio and uncommenting any one of these three lines, the code works as expected, downloading the PDF file to the location.

When publishing to IIS, only the last line (Which just points to a PDF file a local site) will download the file to the location. If I uncomment just one of the first two lines, the code falls into a catch block and displays a 403 error in the comments textbox

I guess this is some sort of SSRS issue since this is only happening to the SSRS URLs but I can't figure out what the problem would be?

NB

http://server-name1/ReportServer_REPORTSDB is a SSRS 2016 server

http://server-name2/ReportServer_REPORTSDB is a SSRS 2008R2 server

This is not my code, but the documentation suggests the line

client.Headers.Add("user-agent", "Document download")

is to prevent a 500 error

SE1986
  • 2,534
  • 1
  • 10
  • 29
  • Since you're getting a 403 error in response to the request for the SSRS report, it's likely that the account your webserver is using to authenticate with the SSRS report server doesn't have permissions to access those reports. This would explain why it works on your local site, as your account likely has access to them. I ran into this problem before and it was the permissions causing the issue. – Jack Oct 30 '18 at 17:30
  • Thanks. How do I find what account the webserver is using? – SE1986 Oct 30 '18 at 17:30
  • It depends on what kind of authentication you're using, and what version of IIS you're using. You should be able to google it pretty easily (that's all I did). – Jack Oct 30 '18 at 17:37

0 Answers0