我们注意到,在我们的 Blazor 服务器端应用程序中,用户可以无意中多次单击按钮。如何使用 Blazor 框架中可用的选项防止这种情况发生?
只要他们点击按钮,就可以将按钮的文本更改为“正在处理...”这样简单的事情就可以满足我们的要求,但我不确定如何实现这一点。单击事件的处理程序需要几秒钟的时间来处理。
任何指针?
当我们最初创建服务器端 blazor 应用程序(ASP.NET Core Web 应用程序)时,我们没有启用身份验证。我们现在想启用 Windows 身份验证。
我创建了一个带有 Windows 身份验证的测试 Web 应用程序,并尝试将缺失的位添加到我们现有的 Web 应用程序中。以下是我所做的更改:
<Router AppAssembly="@typeof(Program).Assembly">
<Found Context="routeData">
<AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
</Found>
<NotFound>
<CascadingAuthenticationState>
<LayoutView Layout="@typeof(MainLayout)">
<p>Sorry, there's nothing at this address.</p>
</LayoutView>
</CascadingAuthenticationState>
</NotFound>
</Router>
Run Code Online (Sandbox Code Playgroud)
@using Microsoft.AspNetCore.Authorization
@using Microsoft.AspNetCore.Components.Authorization
Run Code Online (Sandbox Code Playgroud)
@code {
[CascadingParameter]
private Task<AuthenticationState> authenticationStateTask { get; set; }
private async Task LogUsername()
{
var authState = await authenticationStateTask;
var user = authState.User;
if (user.Identity.IsAuthenticated)
{
Console.WriteLine($"{user.Identity.Name} …
Run Code Online (Sandbox Code Playgroud)