Articles in this section
Category / Section

How to pass authorization header from report service requests in ASP.NET Core 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 Core 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 client-side and pass as an argument for the Ajax-before-load event as shown in the following code snippet.

Index.cshtml

@{ 
    ViewData["Title"] = "ReportViewer ASP.NET CORE Support"; 
} 
<style> 
    body, html, #reportviewer { 
        overflow: hidden !important; 
        height: 100%; 
        width: 100%; 
    } 
</style> 
<ej-report-viewer id="container" report-service-url="/Home" processing-mode="Remote" ajax-before-load="ajaxBeforeLoad"></ej-report-viewer> 
 
<ej-script-manager></ej-script-manager> 
<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 (HomeController) from Authorization key using HttpContext in PostReportAction as shown in the following code snippet.

HomeController.cs

public partial class HomeController : Controller, IReportController 
{ 
        private IMemoryCache _cache; 
        private IHostingEnvironment _hostingEnvironment; 
        private Microsoft.Extensions.Primitives.StringValues headerContent; 
 
        public HomeController(IMemoryCache memoryCache, IHostingEnvironment hostingEnvironment) 
        { 
            _cache = memoryCache; 
            _hostingEnvironment = hostingEnvironment; 
        } 
 
        public ActionResult Index() 
        { 
            return View(); 
        } 
 
        public IActionResult Error() 
        { 
            return View(); 
        } 
  
        [HttpPost] 
        public object PostReportAction([FromBody] Dictionary<string, object> jsonResult) 
        { 
            if (jsonResult != null) 
            { 
                HttpContext.Request.Headers.TryGetValue("Authorization", out headerContent); 
            } 
            return ReportHelper.ProcessReport(jsonResult, this, this._cache); 
        } 
}

 

Please download the sample for authorization header from here


Conclusion

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

You can refer to our ASP.NET Core ReportViewer  feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our ASP.NET Core ReportViewer  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