.net core 2.1 linux 容器中的报表服务器身份验证
Report Server authentication in .net core 2.1 linux container
我正在将 .net core 2.1 应用程序从 windows 服务器迁移到 linux 容器。它使用 SQL Server 2008 报表服务器。
IIS(windows 服务器)上的旧应用程序版本是 运行,已配置身份的应用程序池(活动目录用户)。
新的应用程序版本 运行 在使用 kestrel .net 核心服务器独立的 alpine 容器上,没有配置身份。
当应用程序尝试访问 SQL Server 2008 报表服务器时出现错误:
LoadReport 错误:发生一个或多个错误。 (在此平台上使用默认凭据无法进行 NTLM 身份验证。)
如何在基于 linux 容器的新应用程序中配置凭据(用户名和密码)(与我的旧应用程序池中的一组相同)?
我的一部分 appsettings.json:
"Reporting": {
"ServerUrl": "http://myserver/ReportServer",
"ReportPath": "/Folder/Reports/"
},
部分源码:
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);
}
Microsoft don't provide support for .NET Core/.NET 5, since the SSRS
library is intricately linked with WebForms, which are no longer
supported.
参考这个link
通常,我们在 ASP.NET MVC 中使用 NetworkCredential
选项来传递用户名和密码。
您可以向 ReportSettings.Credential
提供报表服务器的用户名和密码,如下所示。
配置:
"Reporting": {
"ServerUrl": "http://myserver/ReportServer",
"ReportPath": "/Folder/Reports/",
"UserName": "xxxxxx",
"Password": "yyyyyy"
},
源代码:
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;
}
我正在将 .net core 2.1 应用程序从 windows 服务器迁移到 linux 容器。它使用 SQL Server 2008 报表服务器。
IIS(windows 服务器)上的旧应用程序版本是 运行,已配置身份的应用程序池(活动目录用户)。 新的应用程序版本 运行 在使用 kestrel .net 核心服务器独立的 alpine 容器上,没有配置身份。
当应用程序尝试访问 SQL Server 2008 报表服务器时出现错误: LoadReport 错误:发生一个或多个错误。 (在此平台上使用默认凭据无法进行 NTLM 身份验证。)
如何在基于 linux 容器的新应用程序中配置凭据(用户名和密码)(与我的旧应用程序池中的一组相同)?
我的一部分 appsettings.json:
"Reporting": {
"ServerUrl": "http://myserver/ReportServer",
"ReportPath": "/Folder/Reports/"
},
部分源码:
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);
}
Microsoft don't provide support for .NET Core/.NET 5, since the SSRS library is intricately linked with WebForms, which are no longer supported.
参考这个link
通常,我们在 ASP.NET MVC 中使用 NetworkCredential
选项来传递用户名和密码。
您可以向 ReportSettings.Credential
提供报表服务器的用户名和密码,如下所示。
配置:
"Reporting": {
"ServerUrl": "http://myserver/ReportServer",
"ReportPath": "/Folder/Reports/",
"UserName": "xxxxxx",
"Password": "yyyyyy"
},
源代码:
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;
}