您好,我尝试访问报表服务器URL时出现以下错误。如何将Windows凭据传递给ssrs报告。对于您的信息,报表服务器在不同的服务器中配置,因此它将要求身份验证登录。请帮忙。感谢
System.Net.WebException:请求失败,HTTP状态为401: 未经授权。在 Microsoft.Reporting.WebForms.Internal.Soap.ReportingServices2005.Execution.RSExecutionConnection.GetSecureMethods() 在 Microsoft.Reporting.WebForms.Internal.Soap.ReportingServices2005.Execution.RSExecutionConnection.IsSecureMethod(字符串 methodname)at Microsoft.Reporting.WebForms.Internal.Soap.ReportingServices2005.Execution.RSExecutionConnection.SetConnectionSSLForMethod(字符串 methodname)at 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.RSExecutionConnection.LoadReport(字符串 报告,字符串HistoryID)at Microsoft.Reporting.WebForms.SoapReportExecutionService.LoadReport(字符串 报告,字符串historyId)at Microsoft.Reporting.WebForms.ServerReport.EnsureExecutionSession()at Microsoft.Reporting.WebForms.ServerReport.SetParameters(IEnumerable`1 参数)
答案 0 :(得分: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;
}
}
}