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.