2 回答
TA贡献1829条经验 获得超7个赞
将两者 app.UseAuthentication()和app.UseAuthorization() 之后 app.UseRouting()
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.UseEndpoints(routes =>
{
routes.MapDefaultControllerRoute();
});
TA贡献1877条经验 获得超1个赞
如果您发送带有授权令牌的请求,并且Startup.cs文件中未设置服务器授权,则 API 将返回错误消息<Called method> contains authorization metadata, but a middleware was not found that supports authorization...
解决方法是在Startup.cs文件中添加以下行,BETWEENapp.UseRouting()和app.UseEndpoints(...):
app.UseRouting();
//AUTHORIZING
app.UseAuthentication();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapRazorPages();
endpoints.MapControllers();
endpoints.MapFallbackToFile("index.html");
});
- 2 回答
- 0 关注
- 184 浏览
添加回答
举报