我正在创建一个与身份服务器集成的Blazor WebAssembly
应用程序。我对身份验证有一些问题,因为当我将API称为token expired时,这里是帖子(我仍然在四处寻找解决方案)。因此,我删除了身份验证,现在我面临的另一个问题是,我无法在任何机器上复制,但只有客户端可以这样做:
有一个包含条目列表的主页。在此页面中,用户可以单击链接创建新条目。用户可以插入您的条目。如果用户单击链接以查看主页,则会出现错误,因为Blazor找不到该页面。
Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer100未处理异常呈现组件: Arg_NullReferenceException System.NullReferenceException: Arg_NullReferenceException at Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync() at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle) d.printErr @ blazor.webassembly.js:1
我在页面上的OnInitializedAsync
很简单
@inject AuthenticationStateProvider AuthenticationStateProvider
private bool _isLock = false;
private IEnumerable<PublicationPlanUI> _data = new List<PublicationPlanUI>();
private string _errorService = "";
private string _username = "";
protected override async Task OnInitializedAsync()
{
var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
var user = authState.User;
_username = user.Identity.Name;
if (!string.IsNullOrEmpty(_username) && user.Identity.IsAuthenticated)
{
IEnumerable<Domain.PublicationPlan> records;
if (user.Identity.IsAuthenticated && user.IsInRole("Admin"))
records = await _service.GetListWithDetails();
else
records = await _service.GetListWithDetails(_username);
if (records != null)
_data = _mapper.Map<List<PublicationPlanUI>>(records);
var status = await _user.GetStatus(_username);
_isLock = status.IsPublicationClosed;
}
}
所有变量都被初始化。我找不到是什么导致了这个错误。我能清楚地看到有一个Arg_NullReferenceException
,但我找不到哪里。
发布于 2021-06-25 14:31:28
在此方法中返回一个空值:
保护覆盖异步任务OnInitializedAsync()
您需要检查以下对象为null "authState“和"user”,如果它们不是,则用逻辑处理,否则执行其他操作。
你好,JS
https://stackoverflow.com/questions/68130402
复制相似问题