@inject AuthenticationStateProvider AuthenticationStateProvider
@code {
private async Task
private async Task GetCurrentUserNameAsync()
{
var authState = await GetAuthenticationStateAsync();
return authState.User.Identity.Name;
}
}
var reportViewer = new ReportViewer();
var reportServerUrl = "http://localhost/ReportServer"; var reportPath = "/Reports/MyReport";
var reportUserName = await GetCurrentUserNameAsync(); var reportParameter = new ReportParameter("UserName", reportUserName);
reportViewer.ProcessingMode = ProcessingMode.Remote; reportViewer.ServerReport.ReportServerUrl = new Uri(reportServerUrl); reportViewer.ServerReport.ReportPath = reportPath;
reportViewer.ServerReport.SetParameters(new[] { reportParameter });
注意:确保安装最新版本的blazor报告集成NuGet包。此外,你必须在Microsoft.AspNetCore.Components中使用依赖注入