开发者

Do we need to Response.Clear in custom HandleErrorAttribute?

开发者 https://www.devze.com 2023-01-31 12:40 出处:网络
I am reading Pro ASP.NET MVC 2 Framework by Steven Sanderson (Apress) and I see this code for a custom HandleErrorAttribute:

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号