내가 만들고 SSRS에서 PDF 보고서를 다운로드하려면이 code을 사용하고 있습니다, 그러나 나는 다음과 같은 오류가 나타날 수SQL Server Reporting Service를 실행할 때 "원격 서버에서 오류를 반환했습니다 : (401) Unauthorized"문제를 해결하는 방법?
The remote server returned an error: (401) Unauthorized.
내 코드는 다음과 같습니다
protected void Page_Load(object sender, EventArgs e)
{
MemoryStream ms;
// this name is what the user will see when they are prompted for download.
string customFileName = "NewFileName.pdf";
if (!this.IsPostBack)
{
try
{
string strRequest = "http://myServer.com/ReportServer?%2fmetadata_report%2fMetadataReport1&rs%3aCommand=Render&rs%3AFormat=PDF&grpId=3";
WebRequest request = WebRequest.Create(strRequest);
request.ContentType = "application/pdf";
string userName = "username";
string password = "password";
string domain = "myServer.com";
// Create and then pass in network credentials to acecss the reporting server
System.Net.NetworkCredential credentials = new NetworkCredential(userName, password, domain);
request.Credentials = credentials;
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
using (response)
{
// Get the stream from the server
using (Stream stream = response.GetResponseStream())
{
// Use the ReadFully method from the link above:
byte[] data = ReadFully(stream, response.ContentLength);
// Return the memory stream.
ms = new MemoryStream(data);
}
}
// Clear out the headers that may already exist, then set content type and add a header to name the file
Response.Clear();
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "inline; ");
//// Write the memory stream containing the pdf file directly to the Response object that gets sent to the client
ms.WriteTo(Response.OutputStream);
}
}
}
어떤 도움이 많이 주시면 감사하겠습니다.
안녕하세요. 허가 문제입니다. 보고서 서버 구성 자체를 설정해야한다고 생각합니다. 나는 [here] 코드 (http://msdn.microsoft.com/en-us/library/microsoft.reporting.webforms.ireportservercredentials (v = vs 80) .aspx)를 개발했지만 여전히 나에게 _ "HTTP 상태 401 : Unauthorized"_ 오류로 요청이 실패했습니다. 어떠한 제안? 고맙습니다. – Fred