Click here to Skip to main content
15,881,898 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi Everyone,

How to access SSRS Report Server and download Report (.rdl) with dynamic parameters.

Currently I am getting the following exception.
The HTTP request is unauthorized with client authentication scheme 'Ntlm'. The authentication header received from the server was 'Basic realm=""'.


Can someone help me to resolve this issue.

What I have tried:

My Code is :
[HttpPost]
       public IActionResult Index(ReportServer model)
       {
           ReportServer reportServer = _appSettings.ReportServer;
           reportServer.BirthId = model.BirthId;
           reportServer.ReportName = model.ReportName;
           _logger.LogInformation("---------------Report Execution Started------------------------");
           _logger.LogInformation($"entity: {JsonConvert.SerializeObject(reportServer)}");
           ReportResponse result = null;
           try
           {
               ReportSettings reportSettings = new ReportSettings()
               {
                   ReportServer = reportServer.Name,
                   Credential = reportServer.UserName.Contains("\\") ?
                   new NetworkCredential(reportServer.UserName, reportServer.Password) :
                   new NetworkCredential(reportServer.UserName, reportServer.Password, reportServer.Domain)
               };
               _logger.LogInformation($"reportSettings: {JsonConvert.SerializeObject(reportSettings)}");
               ServerReport serverReport = new ServerReport(reportSettings);
               ReportRequest reportRequest = new ReportRequest()
               {
                   Name = reportServer.ReportName,
                   Path = $"{reportServer.BirthReportPath}/{reportServer.ReportName}",
                   RenderType = ReportRenderType.Pdf,
                   ExecuteType = ReportExecuteType.Export,
                   Reset = true

               };

               reportRequest.Parameters.Add("BirthId", reportServer.BirthId);
               _logger.LogInformation("serverReport.Execute method execution started ");
               result = serverReport.Execute(reportRequest);
               _logger.LogInformation($"serverReport.Execute method execution Ended. Statue:{result.Status},Message:{result.Message}");
               _logger.LogInformation("---------------Report Execution Started------------------------");
               if (result.Data.Stream != null)
               {
                   byte[] streamData = result.Data.Stream;
                   result = null;
                   return File(streamData, "application/pdf", reportServer.ReportName);
               }
               else
               {
                   return NotFound(reportServer.ReportName + " Report Not Found" + System.Environment.NewLine + "Error Message=" + result.Message);
               }
           }
           catch (Exception ex)
           {
               _logger.LogInformation("---------------Exception------------------------");
               _logger.LogError(ex, ex.Message);
               return RedirectToAction("Error");
           }
           finally
           {
               result = null;
           }
       }


How to send the authentication type in this code.

Thanks.
Posted
Updated 3-Jan-23 20:40pm
Comments
Richard Deeming 16-Sep-21 9:50am    
What library are you using to call SSRS from .NET Core? Last time I checked, Microsoft don't provide support for .NET Core / .NET 5, since the SSRS library is intricately linked with WebForms, which are no longer supported.
suman palla 16-Sep-21 10:17am    
Hi Richard,
using AspNetCore.Reporting, Version=2.1.0.0,
Richard Deeming 16-Sep-21 10:21am    
It might be worth seeing whether anyone else has encountered that issue, and reporting it if not:
Issues · amh1979/AspNetCore.Reporting · GitHub[^]

1 solution

Hi Suman,
Were you able to fix the NTLM issue, could you please help as am also facing the same issue.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900