Report Server authentication in .net core 2.1 linux container

Viewed 203

I am migrating a .net core 2.1 app from windows server to linux container. It uses SQL Server 2008 report server.

The old app version is running on IIS (windows server), application pool with identity configured (active directory user). The new app version is running on an alpine container using kestrel .net core server standalone, no identity configured.

When the app tries to reach SQL Server 2008 report server there is an error: LoadReport error: One or more errors occured. (NTLM authentication is not possible with default credentials on this platform.)

How can I configure credentials (username and password)(same one set in my old application pool) in my new app based on linux container?

Part of my appsettings.json:

  "Reporting": {
    "ServerUrl": "http://myserver/ReportServer",
    "ReportPath": "/Folder/Reports/"
  },

Part of the source code:

private ServerReport PrepararRelatorio()
{

    ReportSettings settings = new ReportSettings
    {
        ReportServer = this.configuration["Reporting:ServerUrl"]
    };
    
    ServerReport serverReport = new ServerReport(settings);

    return serverReport;
}

protected FileContentResult CarregarRelatorio(
    string nomeRelatorio,            
    string extensao,
    Dictionary<string,string> parametros)
{
    var renderType = this.ObterTipoRenderizacao(extensao);
    if (ReportRenderType.Null.Equals(renderType))
    {
        throw new BusinessException("Erro ao definir o tipo do arquivo a ser exportado.");
    }


    ServerReport serverReport = this.PrepararRelatorio();

    

    ReportRequest request = new ReportRequest
    {
        RenderType = renderType,
        Path = this.configuration["Reporting:ReportPath"] + nomeRelatorio,
        Name = nomeRelatorio,
        ExecuteType = ReportExecuteType.Export,
        Parameters = parametros
    };

    ReportResponse response = serverReport.Execute(request);
    if (response.Status != 0)
    {
        throw new BusinessException(response.Message);
    }

    return File(response.Data.Stream, response.Data.MimeType, nomeRelatorio + "." + extensao);
}
1 Answers

Microsoft don't provide support for .NET Core/.NET 5, since the SSRS library is intricately linked with WebForms, which are no longer supported.

Refer this link

Usually, we use NetworkCredential option to pass username and password while in ASP.NET MVC.

You can able to supply report server's username and password to ReportSettings.Credential as shown in below.

Configuration:

"Reporting": {
    "ServerUrl": "http://myserver/ReportServer",
    "ReportPath": "/Folder/Reports/",
    "UserName": "xxxxxx",
    "Password": "yyyyyy"
  },

Source Code:

private ServerReport PrepararRelatorio()
{

    ReportSettings settings = new ReportSettings
    {
        ReportServer = this.configuration["Reporting:ServerUrl"],
        Credential = NetworkCredential(this.configuration["Reporting:UserName"], this.configuration["Reporting:Password"])
    };
    
    ServerReport serverReport = new ServerReport(settings);

    return serverReport;
}
Related