Page 129 - DCAP312_WEB_TECHNOLOGIES_II
P. 129
Unit 6: Error Handling
exception message, exception type, the stack trace, and the inner exceptions. Only a vague “An Notes
error has occurred.” message is sent back to remote clients for exceptions by default. For model
states, any model error messages are sent to remote clients. Model error exceptions, however,
are considered detail and will not get sent to remote clients by default.
You can choose to override when the error detail gets sent back to clients directly on your
HttpConfiguration object:
config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.LocalOnly;
config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always;
config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Never;\
6.5.4 Applying Error Handling to Handle Invalid Model States
One especially common use of WebAPI’s error handling is to immediately return an error if the
model state is invalid. This can be done fairly easily by implementing the following action filter:
public class ValidationFilterAttribute : ActionFilterAttribute
{
public override void OnActionExecuting(HttpActionContext
actionContext)
{
if (!actionContext.ModelState.IsValid)
{
actionContext.Response=actionContext.Request.CreateErrorResponse(
HttpStatusCode.BadRequest, actionContext.ModelState);
}
}
}
Attempting to use the JScript Error object in an ASP.NET page may product
unintended results. This results from the potential ambiguity between the
JScript Error object and the Error event of the ASP.NET page. Use the System.
Exception class instead of the Error object for error handling in ASP.NET pages.
ASP.NET 2.0 Crash Case: Unhandled Exceptions
Problem Description
Once in a while ASP.NET crashes and we see events in the system event log like this one
Event Type: Warning
Event Source: W3SVC
Event Category: None
Event ID: 1009
Date: 2006-04-25
Time: 09:41:22
PM User: N/A
Contd...
LOVELY PROFESSIONAL UNIVERSITY 123