1

1 つの Web アプリ (mvc 4) を作成して、(メンバーシップ プロバイダーを使用して) 顧客が登録されているレポート (SSRS 2008) を表示することを承認しますが、レポート サーバーへのアクセス権はありません。

リンクに基づいてMVC4でリモートReportViewer aspxページをレンダリングするにはどうすればよいですか? 、Elsimerの最新の回答を実装しましたが、pdfファイルとしてダウンロードするとうまくいきます。

しかし、上記のリンクに記載されているのと同じコードを使用して html としてレンダリングしようとすると、レポート サーバーにアクセスするための Windows 資格情報が要求されます。

そのため、コードを介してレポートサーバー内のすべてのレポートにアクセスできる一般的な資格情報を提供しています。ただし、クライアント側のブラウザーで html として表示しようとすると、レポート サーバーの資格情報が要求されます。レポートは表示されますが、画像とグラフは認証情報なしでは表示されません。

アドバイスしてください、私はこれを解決するために多くのことを試みました。しかし運がない。

私のコントローラーと資格情報クラスのコードは次のとおりです。

[Route("report/MonthlySummary")]
    [ValidateAntiForgeryToken]
    public ActionResult MonthlySummary(MonthlyReportParameters model)
    {


        if (ModelState.IsValid)
        {
            try
            {
                var actionType = model.ActionType;
                if (actionType == "View Report")
                {
                    return ExportMonthlyReportToHtml(model);
                }
                else if (actionType == "Download pdf report")
                {
                    return ExportMonthlyReportToPdf(model);
                }
            }
            catch (Exception ex)
            {
        //Logging errors
            }
        }
        return null;
    }

    private ActionResult ExportMonthlyReportToHtml(MonthlyReportParameters monthlyParams)
    {
        ReportViewer reportViewer = BuildMonthlyReport(monthlyParams);
        reportViewer.ServerReport.Refresh();
        byte[] streamBytes = null;
        string mimeType = "";
        string encoding = "";
        string filenameExtension = "";
        string[] streamids = null;
        Warning[] warnings = null;

        //To view the report in html format
        streamBytes = reportViewer.ServerReport.Render("HTML4.0", null, out mimeType, out encoding, out filenameExtension, out streamids, out warnings); 
        var htmlReport = File(streamBytes, "text/html");           
        return htmlReport;
    }

    private static ReportViewer BuildMonthlyReport(MonthlyReportParameters model)
    {
        ReportViewer reportViewer = new Microsoft.Reporting.WebForms.ReportViewer();
        try
        {
            var rptParameters = new List<ReportParameter>
            {
                //Building parameters
            };

            reportViewer.ProcessingMode = ProcessingMode.Remote;
            reportViewer.ServerReport.ReportPath = "/reportFolder/reportName"; 
            var reportServerUrl = ConfigurationManager.AppSettings["ReportServerUrl"];
            if(!string.IsNullOrEmpty(reportServerUrl))
            {
                reportViewer.ServerReport.ReportServerUrl = new Uri(reportServerUrl);
            }

            reportViewer.ServerReport.ReportServerCredentials = new ReportServerCredentials();
            reportViewer.ServerReport.SetParameters(rptParameters);
        }
        catch (Exception ex)
        {
            var errorMessage = ex.Message;
            //TODO: handle errors;
        }
        return reportViewer;
    }


    public sealed class ReportServerCredentials : IReportServerCredentials
{
    public bool GetFormsCredentials(out Cookie authCookie, out string userName, out string password, out string authority)
    {
        authCookie = null;
        userName = null;
        password = null;
        authority = null;
        return false;
    }

    public WindowsIdentity ImpersonationUser
    {
        get
        {
            return null;
        }
    }

    public ICredentials NetworkCredentials
    {
        get
        {
            string userName = ConfigurationManager.AppSettings["ReportUserName"];

            if ((string.IsNullOrEmpty(userName)))
            {
                throw new Exception("Missing user name from web.config file");
            }

            string password = ConfigurationManager.AppSettings["ReportPassword"];

            if ((string.IsNullOrEmpty(password)))
            {
                throw new Exception("Missing password from web.config file");
            }

            string domain = ConfigurationManager.AppSettings["DomainName"];

            if ((string.IsNullOrEmpty(domain)))
            {
                throw new Exception("Missing domain from web.config file");
            }

            return new NetworkCredential(userName, password, domain);
        }
    }

}

前もって感謝します、

4

0 に答える 0