开发者

custom HandleErrorAttribute

开发者 https://www.devze.com 2023-02-05 00:29 出处:网络
i want to display all errors on the same page (without redirecting/changing page content) where it wa开发者_开发知识库s happened (e.g. javascript alert) and i think that the error-page could load like

i want to display all errors on the same page (without redirecting/changing page content) where it wa开发者_开发知识库s happened (e.g. javascript alert) and i think that the error-page could load like PartialView. i try to create custom HandleErrorAttribute, but it's not working:

public class CustomHandleErrorAttribute : HandleErrorAttribute
{
    public string PartialViewName { get; set; }

    public override void OnException(ExceptionContext filterContext)
    {
        var result = new PartialViewResult();
        result.ViewName = PartialViewName;
        filterContext.Result = result;
    }
}


Try something like this:

protected override void OnException(ExceptionContext filterContext)
{
    filterContext.ExceptionHandled = true;
    this.View("Error").ExecuteResult(this.ControllerContext);
}

More info (including how to make it obey customErrors=RemoteOnly) can be found here:

http://blog.dantup.com/2009/04/aspnet-mvc-handleerror-attribute-custom.html

0

精彩评论

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