[英]C#, ReportViewer: How to make Report Path a URL parameter
我正在研究一種使用報告查看器訪問我們服務器中的 SSRS 報告的解決方案。 目前,服務器 URL 和 repot 路徑是存儲在 Web.config 文件中的值。
Web.config
<add key="ReportServerUrl" value="https://sqlssrs/reportserver"/>
<add key="ReportPath" value="/group/type/report-name"/>
然后將這些值映射到 ReportViewer.aspx.cs 代碼后面。
ReportViewer.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
try
{
// Add the Reporting Server URL
rvSiteMapping.ServerReport.ReportServerUrl = new Uri(ConfigurationManager.AppSettings["ReportServerUrl"].ToString());
//Add the Report Path
rvSiteMapping.ServerReport.ReportPath = ConfigurationManager.AppSettings["ReportPath"].ToString();
rvSiteMapping.ServerReport.Refresh();
}
catch (Exception)
{
}
}
}
我被要求嘗試進行更改,以允許我們將報告路徑值作為查詢字符串參數傳遞。
我不確定如何完成這項任務。 我嘗試執行以下操作。
rvSiteMapping.ServerReport.ReportServerUrl = new Uri("http://sqlssrs/reportserver?pReportPath=/group/type/report-name");
rvSiteMapping.ServerReport.ReportPath= HttpUtility.ParseQueryString(rvSiteMapping.ServerReport.ReportServerUrl).Get("pReportPath");
該代碼不起作用。 它給了我一個錯誤。
Error CS1503 Argument 1: cannot convert from 'System.Uri' to 'string'
是否有可能獲得一些關於如何完成這項任務的指導? 我在 Visual Studio 2015 中運行報告,我想我還需要在項目配置中設置 URL,但我也不確定。
我很感激任何關於如何編程的方向,任何文章,例子,任何可以幫助我完成這項任務的東西。
感謝您分享您的經驗。
伊拉斯莫
報告服務器應包含 URL 並且路徑應包含以“/”開頭的路徑。
我認為正確的方法是:
rvSiteMapping.ServerReport.ReportServerUrl = new Uri("http://sqlssrs/reportserver"); rvSiteMapping.ServerReport.ReportPath= "/group/type/report-name"
您可以使用Request.QueryString["pReportPath"]
來檢索查詢值。
嘗試:
// Add the Reporting Server URL
rvSiteMapping.ServerReport.ReportServerUrl = new Uri(ConfigurationManager.AppSettings["ReportServerUrl"].ToString());
//Add the Report Path
rvSiteMapping.ServerReport.ReportPath = Request.QueryString["pReportPath"];
然后將瀏覽器導航到ReportViewer.aspx?pReportPath=/group/type/report-name
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.