如何更改 Blazor WASM Identity Net Core 3.1 消息“您已注销”、“检查登录状态”和“授权”?

Art*_*r B 9 asp.net-identity webassembly asp.net-core identityserver4 blazor

我需要知道如何个性化和/或更改此消息的语言,我想它与 IdentityServer4 有关。

有任何想法吗?

Sve*_*vek 11

您正在寻找的是RemoteAuthenticatorView .

您可以在官方文档中找到更详细的答案。

@page "/security/{action}"
@using Microsoft.AspNetCore.Components.WebAssembly.Authentication

<RemoteAuthenticatorView Action="@Action">
    @*authentication/login*
    <LoggingIn></LoggingIn> 
    @*authentication/login-callback*
    <CompletingLoggingIn></CompletingLoggingIn>
    @*authentication/login-failed*
    <LogInFailed></LogInFailed>
    @*authentication/logout*
    <LogOut></LogOut>
    @*authentication/logout-callback*
    <CompletingLogOut></CompletingLogOut>
    @*authentication/logout-failed*
    <LogOutFailed></LogOutFailed>
    @*authentication/logged-out*
    <LogOutSucceeded></LogOutSucceeded>
    @*authentication/profile*
    <UserProfile></UserProfile>
    @*authentication/register*
    <Registering></Registering>
</RemoteAuthenticatorView>

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


Art*_*r B 5

有必要在Authentication.razor组件中添加一些标签:

@page "/authentication/{action}"
@using Microsoft.AspNetCore.Components.WebAssembly.Authentication

<RemoteAuthenticatorView Action="@Action">
    <LogInFailed>
        <div class="alert alert-danger" role="alert">@strLogInFailed</div>
    </LogInFailed>
    <LogOut>
        <div class="alert alert-info" role="alert">@strLogOut</div>
    </LogOut>
    <LogOutSucceeded>
        <div class="alert alert-success" role="alert">@strLogOutSucceeded</div>
    </LogOutSucceeded>
    <LoggingIn>
        <div class="alert alert-info" role="alert">@strLoggingIn</div>
    </LoggingIn>
    <CompletingLoggingIn>
        <div class="alert alert-success" role="alert">@strCompletingLoggingIn</div>
    </CompletingLoggingIn>
</RemoteAuthenticatorView>

@code {
    [Parameter] public string Action { get; set; }

    string strLogInFailed = "Your login was not successful.";
    string strLogOut = "Trying to close your session.";
    string strLogOutSucceeded = "Your session has been closed successfully.";
    string strLoggingIn = "Redirecting to the login screen.";
    string strCompletingLoggingIn = "Your login was successful.";
}
Run Code Online (Sandbox Code Playgroud)

我找到了如何做到这一点:自定义身份验证用户界面,顺便说一下,它解释了很多

如何使用 IdentityServer4 保护 Blazor WebAssembly

读完后,我还检查了RemoteAuthenticatorView 类

即使完成了这一点,仍然保留“授权... ”消息。


bla*_*cat 5

更改消息“授权...”

需要添加

<Authorizing>
     <h1>Authorization in progress</h1>
     <p>Only visible while authorization is in progress.</p>
</Authorizing>
Run Code Online (Sandbox Code Playgroud)

文件 App.razor

<CascadingAuthenticationState>
<Router AppAssembly="@typeof(Program).Assembly">
    <Found Context="routeData">
        <AuthorizeRouteView RouteData="@routeData" 
            DefaultLayout="@typeof(MainLayout)">
            <NotAuthorized>
                <h1>Sorry</h1>
                <p>You're not authorized to reach this page.</p>
                <p>You may need to log in as a different user.</p>
            </NotAuthorized>
            <Authorizing>
                <h1>Authorization in progress</h1>
                <p>Only visible while authorization is in progress.</p>
            </Authorizing>
        </AuthorizeRouteView>
    </Found>
    <NotFound>
        <LayoutView Layout="@typeof(MainLayout)">
            <h1>Sorry</h1>
            <p>Sorry, there's nothing at this address.</p>
        </LayoutView>
    </NotFound>
</Router>
Run Code Online (Sandbox Code Playgroud)

你可以找到更多详细的官方文档