While implementing my first restful webapi in .NET Core 3.1 I am trying to implement a fallback routine for 404 Errors. My Startup.cs is actual looking like this:
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers();
// ...
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
// ...
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
endpoints.MapFallbackToController("EndpointNotFound", "Fallback");
});
}
In this configuration, the 404 fallback takes effect before the actual route to the respective controller. I am using the attribute routing in the api controllers. Is it generally possible to use the MapFallbackToController() method inside attribute routing? If not, is there an useful middleware alternative to it?
Greetings