I am looking for option to override default 404 not found Route error in Web API and found this link Override Route
As per the description, I could create class like below
public class HttpNotFoundAwareController:ApiControllerActionSelector
{
public override HttpActionDescriptor SelectAction(HttpControllerContext controllerContext)
{
HttpActionDescriptor descriptor = null;
try
{
descriptor= base.SelectAction(controllerContext);
}
catch(HttpResponseException ex)
{
var code = ex.Response.StatusCode;
}
return descriptor;
}
}
However, this overriding needs to also be registered. From the link it shall be done in WebAPIConfig as below
configuration.Services.Replace(typeof(IHttpControllerSelector), new HttpNotFoundAwareDefaultHttpControllerSelector(configuration));
However I am not sure, how I could register the overriding in .Net Core Startup.cs file? as there is no Replace attribute available for Services.
Can anybody help?