Reputation: 105
I want to handle my net core website able to catch the error and redirect to the error page or other sites if the middleware error or web application build fails at startup.
Methods I have tried
1.Add custom ErrorHandlerMiddleware and redirect page in trycatch,but redirect cause infinite loop and getting error "ERR_TOO_MANY_REDIRECTS"
2.Use "UseExceptionHandler" and errorHandlingPath to Error Controller return and redirect to target page,but getting http error 500
Is it possible to handle redirect to other pages when net core web startup error?
Upvotes: 0
Views: 460
Reputation: 11611
If web application build failed,You may not be able to reach the Error Page
If you want to handle the errors may cause webapplication build failure,you'd better directicty write the response with lambda
app.UseExceptionHandler(x => x.Run(async context=> {
context.Response.StatusCode = 500;
await context.Response.WriteAsync("SomeError");
}));
Upvotes: 1