作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
当我们最初创建服务器端 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>
@using Microsoft.AspNetCore.Authorization
@using Microsoft.AspNetCore.Components.Authorization
@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} is authenticated.");
}
else
{
Console.WriteLine("The user is NOT authenticated.");
}
}
}
最佳答案
显然,我错过了在“项目属性”>“调试”选项卡下选中 Windows 身份验证框。
关于blazor-server-side - 如何在 Blazor 服务器端应用程序中启用/修复 Windows 身份验证?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57940223/
我是一名优秀的程序员,十分优秀!