C# Blazor应用程序中的身份验证处理程序中未调用HandleRequirementAsync
我正在尝试在服务器端Blazor应用程序中使用自定义身份验证处理程序。我的处理程序中有一个断点,但它没有被击中。少了什么 要求 政策 处理者 app.razorC# Blazor应用程序中的身份验证处理程序中未调用HandleRequirementAsync,c#,asp.net-core,blazor,blazor-server-side,C#,Asp.net Core,Blazor,Blazor Server Side,我正在尝试在服务器端Blazor应用程序中使用自定义身份验证处理程序。我的处理程序中有一个断点,但它没有被击中。少了什么 要求 政策 处理者 app.razor <Router AppAssembly="@typeof(Program).Assembly"> <Found Context="routeData"> <RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayo
<Router AppAssembly="@typeof(Program).Assembly">
<Found Context="routeData">
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
</Found>
<NotFound>
<LayoutView Layout="@typeof(MainLayout)">
<p>Sorry, there's nothing at this address.</p>
</LayoutView>
</NotFound>
</Router>
对不起,这个地址什么也没有
[更新]好的,我使用WindowsAuth创建了一个新项目,服务器端blazor,并引入了相同的代码。我可以成功地在auth处理程序中命中断点,因此我正在处理的项目中出现了问题。不确定问题出在哪里。在我的电脑中,断点被击中。你能发布你的App.razor吗?agua-更新的帖子。由于页面级别@attribute[Authorize(Policy=“IsValidUser”)]的原因,是否应该调用处理程序的HandleRequirementAsync方法?
public static class Policies
{
public const string IsValidUser = "IsValidUser";
public static AuthorizationPolicy IsValidUserPolicy()
{
return new AuthorizationPolicyBuilder().RequireAuthenticatedUser()
.Build();
}
}
public class MyAuthHandler : AuthorizationHandler<ValidUserRequirement>
{
protected override Task HandleRequirementAsync(AuthorizationHandlerContext context, ValidUserRequirement requirement)
{
// will do checks against Db here
return Task.CompletedTask;
}
}
// Our services
services.AddAuthorization(config =>
{
config.AddPolicy("IsValidUser", policy => policy.AddRequirements(new ValidUserRequirement(true)));
});
services.AddSingleton<IAuthorizationHandler, MyAuthHandler>();
services.AddScoped<AuthenticationStateProvider, ServerAuthenticationStateProvider>();
@attribute [Authorize(Policy = Policies.IsValidUser)]
<Router AppAssembly="@typeof(Program).Assembly">
<Found Context="routeData">
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
</Found>
<NotFound>
<LayoutView Layout="@typeof(MainLayout)">
<p>Sorry, there's nothing at this address.</p>
</LayoutView>
</NotFound>
</Router>