I am wokring on angular and rendering the SSRS report in app using package. My app is running on
http://localhost:52698/
and SSRS server is on different domain
http:\ssrsservername\ReportServer.
Report server main page rendered successfully. But when I click on any of reports than it gives me error of same origin.
Refused to display 'http://servername/ReportServer/Pages/ReportViewer.aspx?%2fSSRS%2fCascadingReport&rs:Command=Render' in a frame because it set 'X-Frame-Options' to 'sameorigin'.
That's because I am calling report from different domain as per my research.
So, doing by some research I came to know that I need to enable CORS policy in SSRS server so I changes the global.asax file of SSRS with following code.
<%@ Application Inherits="Microsoft.ReportingServices.WebServer.Global" %>
<%@ Import namespace="System.Web" %>
<%@ Import namespace="System.Security" %>
<script runat="server">
private static bool init;
private static object lockObject = new object();
void Application_BeginRequest(object sender, EventArgs e)
{
lock(lockObject)
{
if (!init)
{
HttpContext context = HttpContext.Current;
HttpResponse response = context.Response;
string allow = @"Access-Control-Allow-Origin";
// enable CORS
response.AddHeader(allow, "http://localhost:52698/");
response.AddHeader("X-Content-Security-Policy", "default-src *;");
response.AddHeader(@"Access-Control-Allow-Credentials", "true");
if (context.Request.HttpMethod == "OPTIONS")
{
response.AddHeader(@"Access-Control-Allow-Methods", "GET, POST");
response.AddHeader(@"Access-Control-Allow-Headers", "Content-Type, Accept, Authorization");
response.AddHeader(@"Access-Control-Max-Age", "1728000");
response.StatusCode = 200;
response.End();
HttpApplication httpApplication = (HttpApplication)sender;
httpApplication.CompleteRequest();
}
init = true;
}
else
{
init = false;
}
}
}
But still getting error same error. I followed some articles articles and answers but didn't work for me.
I am new to this and didn't know what to do now and also don't know whats wrong with configurations. What is the correct way to apply CORS policy for SSRS.
I'd appreciate any help. Thanks!