Telerik Reporting REST API not accepting cross origin requests

2 posts, 0 answers
  1. Zach
    Zach avatar
    14 posts
    Member since:
    Jul 2014

    Posted 06 Jun 2018 Link to this post

    My API has a `ReportsController` set up like so:

    using System.Web.Http.Cors;
    using Telerik.Reporting.Cache.File;
    using Telerik.Reporting.Services;
    using Telerik.Reporting.Services.WebApi;

    namespace API.Controllers
    [EnableCors(origins: "*", headers: "*", methods: "*")]
    public class ReportsController : ReportsControllerBase
    static ReportServiceConfiguration configurationInstance;

    static ReportsController()
    configurationInstance = new ReportServiceConfiguration
    HostAppId = "Html5App",
    Storage = new FileStorage(),
    ReportResolver = new ReportTypeResolver(),
    // ReportSharingTimeout = 0,
    // ClientSessionTimeout = 15,

    public ReportsController()
    //Initialize the service configuration
    this.ReportServiceConfiguration = configurationInstance;

    My `App_Start\WebApiConfig.cs`:

        public static class WebApiConfig
            public static void Register(HttpConfiguration config)
                // Web API configuration and services

                // Web API routes

                    name: "DefaultApi",
                    routeTemplate: "api/{controller}/{action}/{id}",
                    defaults: new { id = RouteParameter.Optional }

    My `Global.asax.cs`:

        public class WebApiApplication : System.Web.HttpApplication
            protected void Application_Start()

    My `web.config` has the recommended binding redirects:

            <assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35" culture="neutral" />
            <bindingRedirect oldVersion="" newVersion="" />
            <assemblyIdentity name="System.Net.Http.Formatting" publicKeyToken="31bf3856ad364e35" culture="neutral" />
            <bindingRedirect oldVersion="" newVersion="" />

    As far as I can tell, everything is set up correctly, I can call `api/reports/formats` and see the correct data.  When I try to load this report, I get an error.

    serviceUrl: "http://dev-api/api/reports",
    reportSource: {
    report: "Logic.Reports.Report1, Logic",
    parameters: reportParam

    It displays:
    "Error loading the report viewer's templates. (Template = http://dev-api/api/reports/resources/templates/telerikReportViewerTemplate-html)." 

    on the page, and displays 

    `Failed to load http://dev-api/api/reports/resources/templates/telerikReportViewerTemplate-html: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:64634' is therefore not allowed access.`

    in the Chrome console.  I cannot figure out what I am missing.
  2. Silviya
    Silviya avatar
    440 posts

    Posted 08 Jun 2018 Link to this post

    Hi Zach,

    I did some testing and it seems that the binding redirects are causing the issue. I added proper binding redirects for the referenced assemblies (in my case the assemblies are referring version, but you can replace it with your current version). For example:
    <?xml version="1.0" encoding="utf-8" ?>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
            <assemblyIdentity name="System.Web.Http" culture="neutral" publicKeyToken="31bf3856ad364e35"/>
            <bindingRedirect oldVersion="" newVersion=""/>
            <assemblyIdentity name="System.Net.Http.Formatting" culture="neutral" publicKeyToken="31bf3856ad364e35"/>
            <bindingRedirect oldVersion="" newVersion=""/>

    For more information, please refer to How To: Add Telerik Reporting REST Web API to Web Application (step 2).
    I'm also attaching a video record with steps to enable CORS. Note that the video is silent, in .swf format that can be opened in browser with installed Flash plugin.

    Progress Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top