属性似乎并没有在所有行动 [英] attribute does not seem to act at all

查看:129
本文介绍了属性似乎并没有在所有行动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是用我的控制器操作下,[HandleError]属性有问题 - 它似乎并没有在所有的工作(即它并不重要,如果过滤器存在或不 - 我得到同样的结果... )。当一个异常被抛出,我得到标准红色色调的服务器错误/应用程序错误页面,而不是我的自定义视图。

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 get the same results...). When an Exception is thrown, I get the standard red-toned Server Error in '/' Application error page instead of my custom view.

我发现在这里SO这个问题的几个其他线程,并且在大多数情况下,它似乎在web.config中的customErrors选项设置为在解决了这个问题。它不适合我,所以我需要找到不同的解决方案。

I have found a couple of other threads on the subject here on SO, and in most cases it seems that setting the customErrors option to On in web.config solved the problem. It has not for me, so I need to find a different solution.

我的控制器动作:

[HandleError]
public ActionResult Index()
{
    throw new Exception("oops...");
    return View();
}

在我的web.config文件

In my web.config file

<customErrors mode="On"></customErrors>

我已经确定了Error.aspx文件在共享目录了。我缺少什么?

I have made sure that the Error.aspx file is in the Shared directory, too. What am I missing?

我运行ASP.NET MVC RC Refresh(刷新)。

I am running ASP.NET MVC RC Refresh.

推荐答案

两个有用的东西就知道:

Two useful things to know:

在默认情况下,的HandleError 在开发服务器中运行时,什么都不做。其目的是开发人员展示更多有用信息:

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;
    }

请注意,这起案件是precisely什么 customError 应该控制。如果设置 customError =ON不改变这种行为:

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


  1. 检查语法。

  2. 确保您正在编辑的的Web.config 在项目的根,没有一个在视图。

  3. 确保没有$ C $账套 HttpContext.IsCustomErrorEnabled

  4. 如果这些方法都失败,请尝试在的Web.config开启调试过

  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

其次,某些类型的其中的HandleError 将永远不会处理,特别是ASP.NET编译错误的错误。你不说你遇到哪些错误。

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.

这篇关于属性似乎并没有在所有行动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆