2014-01-13 292 views
0

嗨我尝试访问报表服务器url时出现以下错误。我如何将Windows凭据传递给ssrs报告。对于您的信息,报表服务器配置在不同的服务器上,因此它会要求登录身份验证。请帮忙。谢谢SSRS报告凭证问题

System.Net.WebException:请求失败,HTTP状态401: 未经授权。在 Microsoft.Reporting.WebForms.Internal.Soap.ReportingServices2005.Execution.RSExecutionConnection.GetSecureMethods() 处 微软 Microsoft.Reporting.WebForms.Internal.Soap.ReportingServices2005.Execution.RSExecutionConnection.IsSecureMethod(字符串 方法名)。 Reporting.WebForms.Internal.Soap.ReportingServices2005.Execution.RSExecutionConnection.SetConnectionSSLForMethod(字符串 方法名)在 Microsoft.Reporting.WebForms.Internal.Soap.ReportingServices2005.Execution.RSExecutionConnection.ProxyMethodInvocation.Execute [TReturn](RSExecutionConnection 连接,ProxyMethod 1 initialMethod, ProxyMethod 1 retryMethod)at Microsoft.Reporting.WebForms.Internal.Soap.ReportingServices2005.Execution.RSExecution Connection.LoadReport(字符串 报告,字符串HistoryID)在 Microsoft.Reporting.WebForms.SoapReportExecutionService.LoadReport(字符串 报告,字符串historyId)维持在 Microsoft.Reporting.WebForms Microsoft.Reporting.WebForms.ServerReport.EnsureExecutionSession() .ServerReport.SetParameters(IEnumerable`1 参数)

回答

0

您需要设置

ReportViewer1.ServerReport.ReportServerCredentials = new MyReportServerConnection(); 

在您MyReportServerConnection实现是这样的:

private sealed class MyReportServerConnection : IReportServerConnection2   
    { 
     [System.Runtime.InteropServices.DllImport("advapi32.dll", SetLastError = true)] 
     public static extern bool LogonUser(
       string lpszUsername, 
       string lpszDomain, 
       string lpszPassword, 
       int dwLogonType, 
       int dwLogonProvider, 
       out IntPtr phToken); 

     public WindowsIdentity ImpersonationUser 
     { 
      get 
      { 
       // Use credentials from config file 

       IntPtr userToken = IntPtr.Zero; 

       bool success = LogonUser(
        "reportusername", 
        "reportuserdomain", 
        "reportuserpassword", 
        9,//LOGON_TYPE_NEW_CREDENTIALS 
        3,//LOGON32_PROVIDER_WINNT50 
        out userToken); 

       if (!success) 
       { 
        throw new Exception("Logon user failed"); 
       } 

       return new WindowsIdentity(userToken); 
      } 
     } 

     public ICredentials NetworkCredentials 
     { 
      get 
      { 
       return null; 
      } 
     } 

     public bool GetFormsCredentials(out Cookie authCookie, out string userName, out string password, out string authority) 
     { 
      authCookie = null; 
      userName = null; 
      password = null; 
      authority = null; 

      // Not using form credentials 
      return false; 
     } 

     public Uri ReportServerUrl 
     { 
      get 
      {     
       return new Uri("http://reportserverurl/ReportServer"); 
      } 
     } 

     public int Timeout 
     { 
      get 
      { 
       return 60000; // 60 seconds 
      } 
     } 

     public IEnumerable<Cookie> Cookies 
     { 
      get 
      { 
       // No custom cookies 
       return null; 
      } 
     } 

     public IEnumerable<string> Headers 
     { 
      get 
      { 
       // No custom headers 
       return null; 
      } 
     } 
    }