当在ASP.NET应用程序中使用JWT授权时,可能会遇到HTTP返回代码为404(NotFound)的问题。这通常是由于未正确设置授权中间件和路由配置导致的。
要解决此问题,您可以按照以下步骤操作:
app.UseAuthentication(); app.UseAuthorization();
app.UseEndpoints(endpoints => { endpoints.MapControllers(); });
[Authorize] public class MyController : ControllerBase { // some actions here }
通过以上步骤,您可以解决JWT授权返回NotFound的问题。