I'm trying to download a report (SSRS). More specifically I want to save it in a folder to be able to print it.
It turns out that in development I do not have any problems downloading the report. But at the very least I have to specify that I want to use the credentials by default:
using (var client = new WebClient())
{
client.UseDefaultCredentials = true;
}
However when I try to publish the application to the IIS server I have to specify the credentials (username, password), otherwise I get an Error 403 Forbidden
or 401 Unauthorized
:
client.Credentials = new NetworkCredential("username", "password");
In my perspective, the IIS Application Pool user should have sufficient permissions to download the report, since I have it too.
This is my current code, without the print part.
public string Print(string reportUri, string printerName)
{
using (var client = new WebClient())
{
var path = Path.ChangeExtension(Path.GetTempFileName(), "pdf");
client.UseDefaultCredentials = true;
client.DownloadFile(reportUri, path);
return path;
}
}
What do I have to do to download the production report without specifying the credentials?