【发布时间】:2012-03-18 23:32:12
【问题描述】:
我正在使用 ReportViewer 控件从部署在 IIS7 上的 VS2010 ASP.NET MVC 2 Web 应用程序访问 SSRS 2008 报告,设置如下:
- 已启用表单身份验证和匿名身份验证
- ASP.NET 模拟已禁用
- 应用程序池标识配置为使用本地用户帐户,该帐户有权访问应用程序所需的服务器上的特定文件夹
- 网络服务器不是域的一部分,但 SSRS 服务器在域中
由于我需要使用单独的凭据来访问 SSRS 报告,因此我已经实现了 IReportServerCredentials,如下所述:
我遇到的问题是它总是转到 IReportServerCredentials.ImpersonationUser 而不是 IReportServerCredentials.NetworkCredentials 我需要它去的地方,因为我正在从 web.config 中检索所需的凭据。
也许我在这里遗漏了一些简单的东西,但我尝试了这些设置的不同组合并且没有运气。任何有关我如何使这项工作的指示将不胜感激!
我的代码:
[Serializable]
public sealed class MyReportServerCredentials :
IReportServerCredentials
{
public WindowsIdentity ImpersonationUser
{
get
{
// Use the default Windows user. Credentials will be
// provided by the NetworkCredentials property.
return null;
}
}
public ICredentials NetworkCredentials
{
get
{
// Read the user information from the Web.config file.
// By reading the information on demand instead of
// storing it, the credentials will not be stored in
// session, reducing the vulnerable surface area to the
// Web.config file, which can be secured with an ACL.
// User name
string userName =
ConfigurationManager.AppSettings
["MyReportViewerUser"];
if (string.IsNullOrEmpty(userName))
throw new Exception(
"Missing user name from web.config file");
// Password
string password =
ConfigurationManager.AppSettings
["MyReportViewerPassword"];
if (string.IsNullOrEmpty(password))
throw new Exception(
"Missing password from web.config file");
// Domain
string domain =
ConfigurationManager.AppSettings
["MyReportViewerDomain"];
if (string.IsNullOrEmpty(domain))
throw new Exception(
"Missing domain from web.config file");
return new NetworkCredential(userName, password, domain);
}
}
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;
}
}
this.MyReportView.ServerReport.ReportServerCredentials = new MyReportServerCredentials();
谢谢
【问题讨论】:
标签: asp.net-mvc-2 reporting-services reportviewer