我有一个关于 asp.net core 和 razor 页面的非常简单的问题。
在 c# razor 代码中,我想在某些情况下重定向到另一条路线。如果之前有一个异步(等待)webservice 调用,NavigationManager.NavigateTo 不能正常工作,但也不会抛出异常。
async Task Cancel()
{
var authState = await authenticationStateTask;
var user = authState.User;
if (user.Identity.IsAuthenticated){
// if there's some async webservice call action here,
// NavigationManager.NavigateTo does neither work nor an exception is thrown
NavigationManager.NavigateTo("/Project", true);
}
}
Run Code Online (Sandbox Code Playgroud)
你知道可能是什么原因吗?
NavigationManager.NavigateTo的替代方法是什么?
PS请不要以那种方式提出Response.Redirect(因为,这不适合我)。
var context = new Microsoft.AspNetCore.Http.HttpContextAccessor();
context.HttpContext.Response.Redirect("/Project", true)
Run Code Online (Sandbox Code Playgroud)
亲切的问候,-他。