ActiveReports 12
Viewing Reports from Different Domains using CORS
ActiveReports 12 > ActiveReports User Guide > Viewing Reports > Viewing Reports from Different Domains using CORS

Cross-Origin Resource Sharing is a technology for the web that provides async web operations to directly access reports from different domains. CORS works by adding a special header to responses from a server to the client. If a response contains the Access-Control-Allow-Origin header, then you can directly access the reports from another domain.

The following viewers require CORS:

  1. HTML5 Viewer
  2. HTML Viewer (WebViewer control)
  3. RawHTML (WebViewer control)

The following steps describe how to access reports from different domain using CORS.

  1. Add Global Application Class file (Global.asax) in your application on the service side.
  2. Open the Global.asax.cs file, and add the following code to access reports using cross websites.
    Paste inside the Global.asax.cs
    Copy Code
     protected void Application_BeginRequest(object sender, EventArgs e)
    {
    HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "*");
    if (HttpContext.Current.Request.HttpMethod == "OPTIONS")
    {
    HttpContext.Current.Response.AddHeader("Access-Control-Allow-Methods",
    "GET, POST, OPTIONS");
    HttpContext.Current.Response.AddHeader("Access-Control-Allow-Headers",
    "Content-Type, Accept");
    HttpContext.Current.Response.End();
    }
    }
    Paste inside the Global.asax.vb
    Copy Code
    Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)
    HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "*")
    If HttpContext.Current.Request.HttpMethod = "OPTIONS" Then
    HttpContext.Current.Response.AddHeader("Access-Control-Allow-Methods",
    "GET, POST, OPTIONS")
    HttpContext.Current.Response.AddHeader("Access-Control-Allow-Headers",
    "Content-Type, Accept")
    HttpContext.Current.Response.End()
    End If
    End Sub

    Note:

    • In case of Internet Explorer 9, you need to add $.support.cors = true; code on the client side while initializing the HTML5 Viewer to access reports from a different domain.
    • If you get error 404 or 500 on the report preview, please make sure that your browser supports CORS.

See Also