I have some validation middleware that returns a specific response if some data is missing.
When I make a call with an invalid URL, the middleware is being executed, and the error is sent in the response, but the error states the validation issue, not that the URL is invalid.
So my question is, how do I setup the configure method so that any invalid URL should not execute the middleware and plainly return a 404 error.
Here is my configure method:
public void Configure(IApplicationBuilder app, IHostingEnvironment env)//, ITimingLogger timingLogger
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
}
//app.Use(async (HttpContext context, Func<Task> next) =>
//{
// var timer = new Stopwatch();
// timer.Start();
// await next();
// timer.Stop();
// timingLogger.LogElapsedTime(context.Request.Method, context.Request.Path, timer.ElapsedMilliseconds);
//});
app.UseStaticFiles();
app.UseCookiePolicy();
app.UseMiddleware<RequestResponseLoggingMiddleware>();
app.UseMiddleware<UnhandledExceptionHandlerMiddleware>();
app.UseMiddleware<SubscriptionIdValidatorMiddleware>();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
Thanks