I am reading Pro ASP.NET MVC 2 Framework by Steven Sanderson (Apress) and I see this code for a custom HandleErrorAttribute:
public class RedirectOnErrorAttribute : FilterAttribute, IExceptionFilter
{
public void OnException(ExceptionContext filterContext)
{
// do stuff. finally do:
filterContext.ExceptionHandled = true;
filterContext.HttpContext.Response.Clear();
}
}
Why do we need to Response.Clear() at the end? Thank you.
It removes from the Response any content that might been added by your code before the exception was thrown since very likely it is now useless.
http://msdn.microsoft.com/en-us/library/ms525713(v=vs.90).aspx