Let's say I have an ajax function and an exception is thrown in the SomeAction
action:
function CallAjaxFunction() {
$.ajax({
url: '/Home/SomeAction',
success: function (response) {
//do something
},
error: function (response) {
//redirect to Developer Exception Page to show detailed error
}
});
}
I know that I can redirect to an error page with window.location = "/Home/Error";
, but how would I redirect the browser to the Developer Exception Page to show the more detailed information?
I may be misunderstanding something fundamental here (which is a big reason why I'm asking this question), so I'd appreciate any clarification of concepts.
how would I redirect the browser to the Developer Exception Page to show the more detailed information?
From this doc about "Handle errors in ASP.NET Core", you would find:
Enable the Developer Exception Page only when the app is running in the Development environment. You don't want to share detailed exception information publicly when the app runs in production.
Normally, for better user experience, we do not display error page to client user directly.
If you really want to show browser user the Developer Exception Page while ajax request failed with some error, you can refer to the following sample.
$.ajax({
url: '/Home/MyTestAction',
dataType: "html",
success: function (response) {
//do something
},
error: function (response) {
//console.log(response);
document.write(response.responseText);
}
});
Code of MyTestAction
public IActionResult MyTestAction()
{
Convert.ToDateTime("hello");
return Ok("success");
}
Test Result
If above error callback function executed, the content with detailed error message as below will be displayed in page
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments