2 回答
TA贡献1831条经验 获得超4个赞
后面需要配置aut&auth的中间件:
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
// not here
// app.UseAuthentication();
// app.UseAuthorization();
app.UseResponseCompression();
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseBlazorDebugging();
}
app.UseCors(_myAllowSpecificOrigins);
app.UseStaticFiles();
app.UseClientSideBlazorFiles<Client.Startup>();
app.UseRouting();
// but here
app.UseAuthentication();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapDefaultControllerRoute();
endpoints.MapFallbackToClientSideBlazor<Client.Startup>("index.html");
});
}
它们必须添加到路由下方(在路由之后执行)。
TA贡献1752条经验 获得超4个赞
也许你需要这样的东西:
services.AddMvcCore(options =>
{
var policy = new AuthorizationPolicyBuilder()
.RequireAuthenticatedUser()
.Build();
options.Filters.Add(new AuthorizeFilter(policy));
});
- 2 回答
- 0 关注
- 129 浏览
添加回答
举报