Even though there are many resolutions online none of them are complete.
Here I want to explain briefly how to display the report in an IFRAME in ASP.NET, also how to pass the authentication parameters and finally how to pass report filter parameters.
For the first step to complete we just need any Cognos report URL that either accepts parameters or not. Because any Cognos report will accept an authentication parameter, but for passing additional filter parameters, we need a report URL that accepts parameters from .NET, in other words we need a report URL that is not precompiled and is saved as HTML or an offline report.
The Report URL will have all the special characters that needs to be replaced with the decoded symbols. Refer to here to find all the equivalent decoding characters.
Also, Cognos is always authenticated by AD credentials, so to complete the following example what is needed is an AD account that has access to Cognos reports and the reports should be public reports.
Display Cognos Report in IFRAMES and ASP.Net
HTML
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="IFrameExample.aspx.cs"
Inherits="JnJ.OnLineForms.POC.IFrameExample" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
<style type="text/css">
.style1
{
width: 292px;
}
.style2
{
width: 362px;
}
.style3
{
width: 384px;
}
</style>
</head>
<body style="font-family: Verdana; font-size: 9pt">
<form id="form1" runat="server">
<table border="0">
<tr style="width: 800px">
<td colspan="3">
<iframe frameborder="1" style='width: 1141px; height: 321px;' runat="server" id="filterIFrame"
name="filterIFrame"></iframe>
</td>
</tr>
<asp:Button ID="Submit" runat="server" Text="Submit" OnClick="GetReport" />
</div>
</form>
</body>
</html>
CS file
protected void GetReport(object sender, EventArgs e)
{
Session["UserId"] = "ADUserID";
Session["Pwd"] = "ADPassword";
filterIFrame.Attributes["src"] = "http://10.10.100.100/ibmcognos/cgi-bin/cognos.cgi?b_action=cognosViewer&ui.action=run&ui.object=/content/folder[@name='User POC_DEMO']/folder[@name='POC']/folder[@name='XXX_POC_XXX']/folder[@name='Presentation_V1']/report[@name='POC Report Template']&ui.name=POC Report Template&run.outputFormat=&run.prompt=false
}
In the preceding example, once you run the application, you need to enter the user ID and Password.
Passing Authentication Parameters
CS File
protected void GetReport(object sender, EventArgs e)
{
Session["UserId"] = "ADUserID";
Session["Pwd"] = "ADPassword";
filterIFrame.Attributes["src"] = "http://10.10.100.100/ibmcognos/cgi-bin/cognos.cgi?b_action=cognosViewer&ui.action=run&ui.object=/content/folder[@name='User POC_DEMO']/folder[@name='POC']/folder[@name='XXX_POC_XXX']/folder[@name='Presentation_V2']/report[@name='POC Report Template']&ui.name=POC Report Template&run.outputFormat=&run.prompt=false&CAMUsername=" + Session["UserId"] + "&CAMPassword=" + Session["Pwd"];
}
In the code above, just see the appended "CAMUsername" and "CAMPassword" parameters as query string parameters, once you run the application at this step you will not be prompted for user id and password.
Passing additional filters
In this example let us see that we have an application where we can select parameters and those parameters needs to be passed to Cognos to filter the data.
CS file
protected void GetReport(object sender, EventArgs e)
{
Session["UserId"] = "ADUserID";
Session["Pwd"] = "ADPassword";
filterIFrame.Attributes["src"] = "http://10.10.100.100/ibmcognos/cgi-bin/cognos.cgi?b_action=cognosViewer&ui.action=run&ui.object=/content/folder[@name='User POC_DEMO']/folder[@name='POC']/folder[@name='XXX_POC_XXX']/folder[@name='Presentation_V3']/report[@name='POC Report Template']&ui.name=POC Report Template&run.outputFormat=&run.prompt=false&CAMUsername=" + Session["UserId"] + "&CAMPassword=" + Session["Pwd"] + "&p_Month=" + ddlMonth.SelectedValue.ToString() + "&p_Year=" + ddlYear.SelectedValue.ToString();
}
In the preceding example notice that we have passed the additional parameters "p_Year" and "p_Month". Be careful at this step, sometimes the Cognos default picks up "P_Year" and "P_Month"; in this case you again need to prefix with "p_" to the parameters as in the following:
protected void GetReport(object sender, EventArgs e)
{
Session["UserId"] = "ADUserID";
Session["Pwd"] = "ADPassword";
filterIFrame.Attributes["src"] = "http://10.10.100.100/ibmcognos/cgi-bin/cognos.cgi?b_action=cognosViewer&ui.action=run&ui.object=/content/folder[@name='User POC_DEMO']/folder[@name='POC']/folde[@name='XXX_POC_XXX']/folder[@name='Presentation_V3']/report[@name='POC Report Template']&ui.name=POC Report Template&run.outputFormat=&run.prompt=false&CAMUsername=" + Session["UserId"] + "&CAMPassword=" + Session["Pwd"] + "&p_P_Month=" + ddlMonth.SelectedValue.ToString() + "&p_P_Year=" + ddlYear.SelectedValue.ToString();
}