如何更改刷新 Blazor PWA 应用程序时出现的“正在授权...”消息?

zir*_*zir 7 .net-core progressive-web-apps blazor

当使用浏览器刷新刷新 asp net 托管的 BLAZOR 渐进式 Web 应用程序时,PWA 应用程序将执行身份验证往返。在此时间范围内,主要内容 div 显示文本:“正在授权...”。这个消息来自哪里?我的目标是与此消息一起显示旋转边框,以便用户体验动画。这是我所知道的:

  • wwwroot 中的索引页中会出现初始“正在加载...”消息。
  • 对于每个 AutherizeView,授权部分可用于显示自定义消息。

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

Jus*_*nno 20

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

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

Run Code Online (Sandbox Code Playgroud)

如果您使用默认模板创建了应用程序,您应该会看到一个AuthenticationPage. 该页面有路线@page "/authentication/{action}"

该页面内容看起来像

@page "/authentication/{action}"
@using Microsoft.AspNetCore.Components.WebAssembly.Authentication
<RemoteAuthenticatorView Action="@Action" />

@code{
    [Parameter] public string Action { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

您可以通过添加相应的内容来更改整个模板RenderFragments,可以在此处找到

这是一个示例,其中每个片段都有一个非默认值

@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; }
}
Run Code Online (Sandbox Code Playgroud)