I have asp.net core application. To handle exception i am using one of the extension method from Microsoft.AspNetCore.Diagnostics
app.UseExceptionHandler("/Home/Error");
so when error occurs user gets redirected to error page.
I wanted to know how do i redirect user to certain page based on exception type? something like
if( exception is NotAuthorizedException)
{
// redirect to "Home/NotAuthrozied"
}
else
{
// redirect to "Home/Error"
}
How do i handle this inside app.UseExceptionHandler() method?
I have already looked here but couldnt find anything. I am also trying to avoid creating custom middleware to handle exception.
UseExceptionHandlerconsiders only aboutExceptionHandlingPath(you can check it in its source code). So just use custom middleware, it's pretty easy.