Articles in this section
Category / Section

How to pass the authorization header from report service requests in ASP.NET MVC ReportViewer?

1 min read

You can use the Ajax-Before-Load event to pass the authorization header with report server requests using Syncfusion ASP.NET MVC ReportViewer. The following steps guide you to send the custom headers from client to the server-side using the ‘Ajax-before-load’ event.

1. Create a simple ReportViewer application with the help of getting started documentation.

2. Provide the custom headers in the client-side and pass as an argument for the Ajax-before-load event as shown in the following code snippet.

Default.html

    <div id="ControlRegion" style="height:100% ;position:absolute;">
        <div>
            @(Html.EJ().ReportViewer("reportviewer").ProcessingMode(Syncfusion.JavaScript.ReportViewerEnums.ProcessingMode.Remote).ReportPath("~/App_Data/Grouping Aggregate.rdl").ReportServiceUrl("/api/ReportAPI").AjaxBeforeLoad("ajaxBeforeLoad"))
        </div>
        @(Html.EJ().ScriptManager())
    </div>
    <script type="text/javascript">
        function ajaxBeforeLoad(event) {
            event.headers.push({ Key: 'Authorization', Value: "BearerMyToken" });
        };
    </script>

 

3.  Get the client-side custom header in the controller (ReportAPIController) from Authorization key using HttpContext in PostReportAction as shown in the following code snippet.

ReportAPIController.cs

public class ReportAPIController : ApiController, IReportController
{
        public string HeaderContent = null;
        //Post action for processing the rdl/rdlc report 
        public object PostReportAction(Dictionary<string, object> jsonResult)
        {
            if (jsonResult != null)
            {
                HeaderContent = HttpContext.Current.Request.Headers["Authorization"];
            }
 
            return ReportHelper.ProcessReport(jsonResult, this);
        }
 
        [System.Web.Http.ActionName("GetResource")]
        [System.Web.Http.AcceptVerbs("GET")]
        public object GetResource(string key, string resourcetype, bool isPrint)
        {
            return ReportHelper.GetResource(key, resourcetype, isPrint);
        }
        public void OnInitReportOptions(ReportViewerOptions reportOption)
        {
        }
        public void OnReportLoaded(ReportViewerOptions reportOption)
        {
        }
}

 

Please download the sample for authorization header from here


Conclusion

I hope you enjoyed learning about how to pass the authorization header from report service requests in ASP.NET MVC ReportViewer.

You can refer to our .NET MVC ReportView feature tour page to know about its other groundbreaking feature representations and .NET MVC ReportView documentation, and how to quickly get started for configuration specifications. You can also explore our .NET MVC Gantt example to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied