SSRSレポートビューアー+ ASP.NET資格情報401例外
-
10-07-2019 - |
質問
レポートをSQL2005レポートサーバーに保存しており、このレポートのレンダリングされたPDFを返します。ローカルの* .rdlcファイル(そして私はそれについてブログに書いた)が、*。rdlがレポートサーバーにあるときはそうではない。行に 401 Not Authorized エラーが表示されます...
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ですか?
解決
最終的に問題を突き止めました。ネットワーク管理者はダブルホッピングを無効にしているため、偽装が domain \ jmeyer
として正しく接続している間、アプリケーションは domain \ web01 $
。なぜこのように設定されているのですか?ダブルホッピングは大きなセキュリティホールだからです。 (または、そう言われました。これは The Daily WTF で読むようなものですか?)
ソリューションは、一般的な domain \ ssrs_report_services
ユーザーを作成し、次のネットワーク認証情報でそのユーザーと接続することでした
public class CustomCredentials : 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 null; }
}
public ICredentials NetworkCredentials
{
get { return new NetworkCredential("ssrs_report_services", "password", "domain") ; }
}
}
上記は、インターネット上で見つけることができる古典的なソリューション例です。
他のヒント
"ダブルホッピング"許可されています-Kerberos認証で...(正常に動作している限り!)
所属していません StackOverflow