SQL2005レポートサーバーにレポートを保存しましたが、このレポートのレンダリングされたPDFを返したいと思います。ローカルの*.rdlcファイルを操作しているときにこれを理解しました(そしてそれについてブログに書いています)が、*。rdlがレポートサーバーにあるときはわかりません。行で401NotAuthorizedエラーが発生します...
reportViewer.ServerReport.SetParameters(reportDefinition.ReportParameters);
レポートのレンダリングに使用される方法は次のとおりです。
public byte[] Render(IReportDefinition reportDefinition)
{
var reportViewer = new ReportViewer();
byte[] renderedReport;
try
{
var credentials = new WindowsImpersonationCredentials();
reportViewer.ServerReport.ReportServerUrl = new Uri("http://myssrsbox", UrlKind.Absolute);
reportViewer.ServerReport.ReportServerCredentials = credentials;
reportViewer.ServerReport.ReportPath = reportDefinition.Path;
// Exception is thrown on the following line...
reportViewer.ServerReport.SetParameters(reportDefinition.ReportParameters);
string mimeType;
string encoding;
string filenameExtension;
string[] streams;
Warning[] warnings;
renderedReport = reportViewer.ServerReport.Render(reportDefinition.OutputType, reportDefinition.DeviceInfo, out mimeType, out encoding, out filenameExtension, out streams, out warnings);
}
catch (Exception ex)
{
// log the error...
throw;
}
finally
{
reportViewer.Dispose();
}
return renderedReport;
}
もう1つ欠けているのは、WindowsImpersonationCredentialsクラスです。
public class WindowsImpersonationCredentials : IReportServerCredentials
{
public bool GetFormsCredentials(out Cookie authCookie, out string userName, out string password, out string authority)
{
authCookie = null;
userName = password = authority = null;
return false;
}
public WindowsIdentity ImpersonationUser
{
get { return WindowsIdentity.GetCurrent(); }
}
public ICredentials NetworkCredentials
{
get { return null; }
}
public override string ToString()
{
return String.Format("WindowsIdentity: {0} ({1})", this.ImpersonationUser.Name, this.ImpersonationUser.User.Value);
}
}
あなたが知る必要があるかもしれない他のこと...
- これはイントラネット上で実行されており、偽装がオンになっています。
- ロギングは、偽装ユーザーが正しく設定されていることを示しています。
- これは、Visual Studio(
http://localhost:devport
)で実行している場合は機能し、開発ボックス(http://localhost/myApplication
)で実行している場合は機能します。テストサーバーまたは本番サーバーで実行している場合は機能しません。 - web.configのsystem.net.defaultProxy設定がある場合とない場合の両方で解決策を試しました。どちらも機能しませんでした。
私は何が間違っているのですか?サーバー設定ですか?コードですか?web.configですか?