如何更改刷新 Blazor PWA 应用程序时出现的 "Authorising..." 消息?

How do I change the "Authorising..." message that appears when a Blazor PWA application is being refreshed?

当使用浏览器刷新刷新 asp 网络托管的 BLAZOR 渐进式 Web 应用程序时,PWA 应用程序执行身份验证往返。在此时间跨度内,主要内容 div 显示文本:“Authorising...”。此消息源自何处?我的 objective 是随此消息一起显示微调器边框,以便用户体验动画。这是我所知道的:

但我无法找到默认“授权...”消息的来源。

有两个地方需要你的意向。

首先在您的 App.razor 中。 AuthorizeRouteView 有一个名为 Authorizing 的 属性,您可以在其中添加要在授权期间显示的任何 RenderFragementHere 是设置 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; }
}