我编写了一个指向SSRS 2016的iframe,但每次浏览器都会显示一个进行身份验证的窗口。
有没有办法将凭据传递给服务器以进行身份验证而不向用户显示登录窗口?
答案 0 :(得分:0)
有同样的问题,真的很沮丧。我找到了一个' 脏'通过在PHP中创建一个基本API来解决我的问题。
如果您想尝试此路线,请执行以下操作: 看看这个页面,并在你的PHP中安装这个软件包(自2010年以来它没有更新,但它仍然可以正常工作):https://ssrsphp.codeplex.com/
以下是页面中的示例(如果要将参数传递给报表,则非常有用):
// include the SSRS library
require_once 'SSRSReport.php';
define("REPORT", "/AdventureWorks 2008 Sample Reports/TopStoresBegin");
$settings = parse_ini_file("app.config", 1);
// Create a connection to the SSRS Server
$rs = new SSRSReport(new Credentials($settings["UID"], $settings["PASWD"]),$settings["SERVICE_URL"]);
// Load the report and specify the params required for its execution
$executionInfo = $rs->LoadReport2(REPORT, NULL);
$parameters = array();
$parameters[0] = new ParameterValue();
$parameters[0]->Name = "ProductCategory";
$parameters[0]->Value = "1";
$parameters[1] = new ParameterValue();
$parameters[1]->Name = "StartDate";
$parameters[1]->Value = "1/1/2003";
$parameters[2] = new ParameterValue();
$parameters[2]->Name = "EndDate";
$parameters[2]->Value = "12/31/2003";
$parameters[3] = new ParameterValue();
$parameters[3]->Name = "ProductSubcategory";
$parameters[3]->Value = "2";
$rs->SetExecutionParameters2($parameters);
// Require the Report to be rendered in HTML format
$renderAsHTML = new RenderAsHTML();
// Set the links in the reports to point to the php app
$renderAsHTML->ReplacementRoot = getPageURL();
// Set the root path on the server for any image included in the report
$renderAsHTML->StreamRoot = './images/';
// Execute the Report
$result_html = $rs->Render2($renderAsHTML,
PageCountModeEnum::$Actual,
$Extension,
$MimeType,
$Encoding,
$Warnings,
$StreamIds);
// Save all images on the server (under /images/ dir)
foreach($StreamIds as $StreamId)
{
$renderAsHTML->StreamRoot = null;
$result_png = $rs->RenderStream($renderAsHTML,
$StreamId,
$Encoding,
$MimeType);
if (!$handle = fopen("./images/" . $StreamId, 'wb'))
{
echo "Cannot open file for writing output";
exit;
}
if (fwrite($handle, $result_png) === FALSE)
{
echo "Cannot write to file";
exit;
}
fclose($handle);
}
// include the Report within a Div on the page
echo '<html><body><br/><br/>';
echo '<div align="center">';
echo '<div style="overflow:auto; width:700px; height:600px">';
echo $result_html;
echo '</div>';
echo '</div>';
echo '</body></html>';
然而,根据我的需要,我非常简化了代码。此外,我不得不从它中删除url重写功能,因为它会弄乱服务器会话ID,这反过来意味着如果你对报告有任何下钻,它们将根本不起作用。这是我的代码片段:
/* Load SSRS Library */
require_once 'SSRSReport.php';
/* Load a report - remember that you can set up an external file that would hold the login credentials for you, I left those here for demonstration only*/
define("UID", 'Your user name here');
define("PWD", "Your pass");
define("SERVICE_URL", "Service url for your ssrs");
define("REPORT", "Variable with your 'path to' and name of report");
try
{
$ssrs_report = new SSRSReport(new Credentials(UID, PWD),
SERVICE_URL);
$ssrs_report->LoadReport2(REPORT, NULL);
$htmlFormat = new RenderAsHTML();
$htmlFormat->StreamRoot = './images/';
$result_html = $ssrs_report->Render2($htmlFormat,
PageCountModeEnum::$Estimate,
$Extension,
$MimeType,
$Encoding,
$Warnings,
$StreamIds);
echo $result_html;
}
Catch(SSRSReportException $serviceExcprion)
{
echo $serviceExcprion->GetErrorMessage();
}
所以在我的应用程序中,当我调用我的api时,我会在URL的末尾传递报告的名称和路径(url编码)。然后我在服务器上解码它,PHP SSRS SDK然后记录你抓取报告并将其作为HTML返回(也适用于PDF或CSV的魅力)
所以在iFrame中,我把api的url放在最后的参数中。你可以用这种方式处理任何额外的参数。然后,当我转到我的主应用程序时,我不再看到登录屏幕,报告立即显示。
我发现的一个问题是,仍然,非常偶尔你会以某种方式登出并且可怕的登录界面显示出来,但随后在页面刷新它再次起作用。
希望这有帮助!