【问题标题】:WebException using reportviewer使用报告查看器的 WebException
【发布时间】:2013-09-24 16:23:47
【问题描述】:

我正在尝试通过 ASP.NET Web ReportViewer 控件连接到 ReportingServices:

               rvContract.ProcessingMode = Microsoft.Reporting.WebForms.ProcessingMode.Remote;
            rvContract.ServerReport.ReportServerCredentials = new ReportServerCredentials("myUsername", "myNetworkPassword", "DOMAIN");
            rvContract.ServerReport.ReportServerUrl = new Uri(ReportConfiguration.ReportServerUrl);
            string rptPath = ReportConfiguration.RootPath;
            if (!rptPath.EndsWith("/"))
            {
                rptPath += "/";
            }
            rvContract.ServerReport.ReportPath = rptPath + "AdminReports/Contract";

            List<ReportParameter> reportParams = new List<ReportParameter>();

            if (MkoSession.AccountId.HasValue)
            {
                ReportParameter accountId = new ReportParameter("AccountId", MkoSession.AccountId.Value.ToString());
            }

            rvContract.ServerReport.SetParameters(reportParams);

            rvContract.ShowParameterPrompts = false;
            rvContract.ShowZoomControl = false;

            rvContract.ServerReport.Refresh();
            rvContract.DataBind();

凭证的实现如下所示:

public class ReportServerCredentials : IReportServerCredentials
{
    private string _userName;
    private string _password;
    private string _domain;

    public ReportServerCredentials(string userName, string password, string domain)
    {
        _userName = userName;
        _password = password;
        _domain = domain;
    }

    public WindowsIdentity ImpersonationUser
    {
        get
        {
            // Use default identity.
            return null;
        }
    }

    public ICredentials NetworkCredentials
    {
        get
        {
            // Use default identity.
            return new NetworkCredential(_userName, _password, _domain);
        }
    }

    public bool GetFormsCredentials(out Cookie authCookie, out string user, out string password, out string authority)
    {
        // Do not use forms credentials to authenticate.
        authCookie = null;
        user = null;
        password = null;
        authority = null;
        return false;
    }
}

只是在测试时对我的凭据进行硬编码。在签入之前,我们必须为此创建一个域帐户。

我可以通过浏览器点击 ReportService2005.asmx 和 ReportExecution2005.asmx(这是我的 ReportServerUrl 变成的)没有问题。

当我调用 SetParameters 时,我得到一个 WebException。查看异常中响应中的标头:

{RSNotAuthenticated: 真 RSAuthenticationHeader:.ASPXFORMSAUTH 内容长度:206 缓存控制:私有 内容类型:文本/html;字符集=utf-8 日期:2013 年 9 月 24 日星期二 16:15:08 GMT 位置:/ReportServer/logon.aspx?ReturnUrl=%2freportserver%2fReportExecution2005.asmx 服务器:Microsoft-HTTPAPI/2.0 X-AspNet-版本:2.0.50727

}

这似乎是在告诉我我还没有登录。如果是这样,完全相同的凭据如何让我通过浏览器查看网络服务?

顺便说一句,我确实在 ReportServerCredentials 实现中的每个方法中都设置了断点,并且看到了每个断点命中。不确定这告诉我们什么,但 NetworkCredentials 接口返回了我的网络凭据就好了。

【问题讨论】:

    标签: asp.net reportingservices-2005


    【解决方案1】:

    我想我可能偶然发现了它。以防其他人遇到类似的麻烦。

    首先,我四处寻找,在服务器上找到了报告服务 web.config。看到它使用的是authenticaion mode = forms。

    因此,我实现了 GetFormsCredentials 以返回 true 并传递通用用户名。我从 ReportServer 数据库的 Users 表中得到了这个用户名。

    不再收到 WebException,但我的 ReportViewer 也没有显示。所以,还没有走出困境,但似乎更接近了。

    FWIW,我认为我记得有人说我们的数据库服务器上有奇怪的自定义表单身份验证。所以,对于任何发生这种情况的人,YMMV。所有这些都早于我,所以我不确定如何检查。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-06-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多