当使用浏览器刷新刷新 asp 网络托管的 BLAZOR 渐进式 Web 应用程序时,PWA 应用程序执行身份验证往返。在此时间跨度内,主要内容 div 显示文本:“Authorising...”。这个消息来自哪里?我的目标是与此消息一起显示微调边框,以便用户体验动画。这是我所知道的:
但我无法找到默认“授权...”消息的来源。
最佳答案
有两个地方需要你的意图。
首先是在您的 App.razor
. AuthorizeRouteView
有一个名为 Authorizing
的属性,您可以在其中添加任何 RenderFragement
您想在授权期间显示。 Here是Authorizing...
所在的行设置。
<CascadingAuthenticationState>
<Router AppAssembly="@typeof(Program).Assembly" PreferExactMatches="@true">
<Found Context="routeData">
<AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)">
<Authorizing>
<span>Your spinner goes here</span>
</Authorizing>
<NotAuthorized>
@if (!context.User.Identity.IsAuthenticated)
{
<RedirectToLogin />
}
else
{
<p>You are not authorized to access this resource.</p>
}
</NotAuthorized>
</AuthorizeRouteView>
</Found>
<NotFound>
<LayoutView Layout="@typeof(MainLayout)">
<p>Sorry, there's nothing at this address.</p>
</LayoutView>
</NotFound>
</Router>
</CascadingAuthenticationState>
如果您使用默认模板创建了应用程序,您应该会看到 AuthenticationPage
.本页有路线@page "/authentication/{action}"
.此页面内容看起来像
@page "/authentication/{action}"
@using Microsoft.AspNetCore.Components.WebAssembly.Authentication
<RemoteAuthenticatorView Action="@Action" />
@code{
[Parameter] public string Action { get; set; }
}
您可以通过添加相应的 RenderFragments
来更改整个模板。可以找到 here这是一个示例,其中每个片段都有一个非默认值
@page "/authentication/{action}"
@using Microsoft.AspNetCore.Components.WebAssembly.Authentication
<RemoteAuthenticatorView Action="@Action">
<LoggingIn>
<span>LoggingIn</span>
</LoggingIn>
<Registering>
<span>Registering</span>
</Registering>
<Registering>
<span>LoggingIn</span>
</Registering>
<UserProfile>
<span>UserProfile is loaded....</span>
</UserProfile>
<CompletingLoggingIn>
<span>CompletingLoggingIn</span>
</CompletingLoggingIn>
<LogInFailed>
<span>Login failed. Reason: @context</span>
</LogInFailed>
<LogOut>
<span>Logout from the application</span>
</LogOut>
<LogOut>
<span>CompletingLogOut</span>
</LogOut>
<LogOutFailed>
<span>Logout failed. Reason: @context</span>
</LogOutFailed>
<LogOut>
<span>LogOutSucceeded</span>
</LogOut>
</RemoteAuthenticatorView>
@code{
[Parameter] public string Action { get; set; }
}
关于.net-core - 如何更改 Blazor PWA 应用程序刷新时出现的 "Authorising..."消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66310829/