参考微软官方文档 Require authenticated users,在 ASP.NET 项目中添加下面的代码
builder.Services.AddAuthorization(options =>
{
options.FallbackPolicy = new AuthorizationPolicyBuilder()
.RequireAuthenticatedUser()
.Build();
});
运行时发现对静态文件(static files)不起作用,请问如何解决?
middleware 的顺序引起的,UseAuthorization 需要放在 UseStaticFiles 之前
app.UseAuthorization();
app.UseStaticFiles();