attribute does not seem to act at all

前端 未结 6 906
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-16 17:58

I am having problems using the [HandleError] attribute on my Controller Actions - it doesn\'t seem to work at all (i.e. it doesn\'t matter if the filter is there or not - I

6条回答
  •  暖寄归人
    2020-12-16 18:19

    Two useful things to know:

    By default, HandleError does nothing when running under the development server. The intention is to show developers more useful information:

    public virtual void OnException(ExceptionContext filterContext) {
        if (filterContext == null) {
            throw new ArgumentNullException("filterContext");
        }
    
        // If custom errors are disabled, we need to let the normal ASP.NET
        // exception handler execute so that the user can see useful
        // debugging information.
        if (filterContext.ExceptionHandled
            || ! filterContext.HttpContext.IsCustomErrorEnabled) {
            return;
        }
    

    Note that this case is precisely what customError is supposed to control. If setting customError="On" does not change this behavior:

    1. Check your syntax.
    2. Make sure you're editing the Web.config in the project root, not the one in Views.
    3. Make sure no code sets HttpContext.IsCustomErrorEnabled.
    4. If all else fails, try turning debug off in Web.config

    Second, there certain types of errors which HandleError will never handle, notably ASP.NET compilation errors. You don't say which error you're encountering.

提交回复
热议问题