GetAuthenticationStateAsync was called before SetAuthenticationState
Environment
Product | Progress® Telerik® Reporting |
Description
Error 'GetAuthenticationStateAsync was called before SetAuthenticationState.' is thrown in a Custom Report Source Resolver that uses GetAuthenticationStateAsync.
Error Message
GetAuthenticationStateAsync was called before SetAuthenticationState.
Cause\Possible Cause(s)
The Telerik Reporting REST Service is recommended to be in a Singleton scope. However, the AuthenticationProvider requires utilizing the Scoped option. You can find more information in Accessing an authenticated user outside of a view in Blazor Stack Overflow thread.
Solution
We support accessing the current user inside the CustomReportSourceResolver using our own mechanism as described in ASP.NET Core. How to use information from HttpContext in Custom Report Resolver. For example:
public class CustomReportSourceResolver : IReportSourceResolver
{
public Telerik.Reporting.ReportSource Resolve(string reportId, OperationOrigin operationOrigin, IDictionary<string, object> currentParameterValues)
{
var userClass = new ServiceClass(UserIdentity.Current);
if (!string.IsNullOrEmpty(report))
{
using var context = new DataContext(userClass);
report = (from table in context.Reports where table.Name == report select table.Definition).First();
}
ReportSource updatedReport;
if (string.IsNullOrEmpty(report))
{
throw new System.Exception("Unable to load a report with the specified ID: " + report);
}
else
{
XmlReportSource retreivedReport = new Telerik.Reporting.XmlReportSource { Xml = report };
var conStrMan = new ReportConnectionStringManager(userClass);
updatedReport = conStrMan.UpdateReportSource(retreivedReport);
}
return updatedReport;
}
}
In this way, you are able to get the user and pass it to your AuthenticationProvider.