2012-09-13 2 views
1

내가 만들고 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); 
     } 
    } 
} 

어떤 도움이 많이 주시면 감사하겠습니다.

답변

1
+0

안녕하세요. 허가 문제입니다. 보고서 서버 구성 자체를 설정해야한다고 생각합니다. 나는 [here] 코드 (http://msdn.microsoft.com/en-us/library/microsoft.reporting.webforms.ireportservercredentials (v = vs 80) .aspx)를 개발했지만 여전히 나에게 _ "HTTP 상태 401 : Unauthorized"_ 오류로 요청이 실패했습니다. 어떠한 제안? 고맙습니다. – Fred

0

당신이 시도 할 수 있습니다?

// Create and then pass in network credentials to acecss the reporting server 
CredentialCache cc = new CredentialCache(); 
cc.Add(new Uri("http://myServer.com/"), "Negotiate", new NetworkCredential("Username", "Password", "Domain")); 
request.Credentials = cc; 
+0

안녕하세요, 내 코드를 업데이트했지만 여전히 동일한 오류가 발생합니다. 문제를 일으키는 내 Report Server 구성 (예 : 인증)에 뭔가가 있다고 생각하지 않습니까? 어떠한 제안? 고맙습니다. – Fred

+0

해당 계정을 사용하여 보고서를 열어 보았습니까? –

+0

예. 동일한 계정 (관리자)을 사용하여 보고서를 열 수 있습니다. – Fred

0

나는 지난 주 내내 이렇게 많은 양을 잃었습니다. 제 경우 보고서 정의는 SQL 서버와 IIS가 동일한 서버에 있습니다. 그리고 ssrs 서버에서 보고서를 가져 와서 개발 시스템의 모든 것을 테스트했습니다. 이 시점에서 모든 것이 완벽하게 작동했습니다. 이제 프로덕션 서버에 응용 프로그램을 배포하자마자 오류가 발생했습니다. 개발 용 컴퓨터에서 작동하는 필요한 권한으로 정렬 된 별도의 보고서 사용자가있었습니다. 이중 호핑으로부터 보호하기위한 마이크로 소프트 보안 기능이 제공됩니다. LSA를 사용한다면 충분히 만족 스러울 것입니다. 벌거 벗은 마음을 가장하면서 = 진실은 아무 것도 할 수 없습니다.

내 솔루션은 다음과 마치 마법처럼 일 : 세부 연구 내용은

Method 2: Disable the authentication loopback checkRe-enable the behavior that exists in Windows Server 2003 by setting the DisableLoopbackCheck registry entry in the HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa registry subkey to 1. To set the DisableLoopbackCheck registry entry to 1, follow these steps on the client computer:  Click Start, click Run, type regedit, and then click OK. Locate and then click the following registry subkey: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\LsaRight-click Lsa, point to New, and then click DWORD Value.Type DisableLoopbackCheck, and then press ENTER.Right-click DisableLoopbackCheck, and then click Modify.In the Value data box, type 1, and then click OK.Exit Registry Editor.Restart the computer.Note You must restart the server for this change to take effect. By default, loopback check functionality is turned on in Windows Server 2003 SP1, and the DisableLoopbackCheck registry entry is set to 0 (zero). The security is reduced when you disable the authentication loopback check, and you open the Windows Server 2003 server for man-in-the-middle (MITM) attacks on NTLM.

:

read here가 누군가를 도움이되기를 바랍니다.

감사합니다.

관련 문제