不显示自定义错误页asp

不显示自定义错误页asp

本文介绍了不显示自定义错误页asp.net的MVC的ErrorHandler的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图按照此链接和的但不是显示错误页面,我得到一个HTTP 500内部服务器错误。
我有<的customErrors模式=ON/> 设置在webconfig。我甚至试图运用 [的HandleError] 过滤器,控制器类。我想没有为好。该Error.aspx是present /查看/共享/以及因此它不可能是没有找到文件的情况。

I am trying to follow the examples in this link and this one but instead of showing the error page I get an HTTP 500 Internal server error.I have the <customErrors mode="On" /> set in the webconfig. I have even tried applying the [HandleError] filter to the controller class. I tried without as well. The Error.aspx is present in /Views/Shared/ as well so it couldn't be a case of no file found.

我在控制器的操作方法扔了DivideByZero例外。我想也这样做,这样我可以为所有需要它们的动作指定单独的错误页面。

I threw a DivideByZero exception in my controller's action method. I want to follow that example so that I can specify a separate error page for all the actions that need them.

我使用,我创建了一个空白的项目ASPX视图引擎。这不应该是它的原因吧?我还使用一个母版页这一点。我可能会错过什么吗?

I am using the aspx view engine in a blank project that I created. That should not be the reason for it right?. I am also using a master page for this. Anything that I could be missing?

感谢

编辑 - 添加code

我添加了这个$​​ C $ C到一个新的项目,并提出在web.config条目&LT;的customErrors模式=ON/&GT;

I added this code to a new project and made the web.config entry <customErrors mode="On" />

 [HandleError]
    public class HomeController : Controller
    {
        //
        // GET: /Home/
        [HandleError]
        public ActionResult Index()
        {

            throw new DivideByZeroException();
            return View();
        }

    }

它没有工作!然后我评论说DivideByZeroException并在ASPX视图刚添加和无效Model.Property。在这两种情况下,我得到了内部服务器错误。我所做的一切有工作要做按文档。我看到了很多有同样问题的其他人,不能够解决它。这是MVC 3中的错误?

It didnt work! Then I commented that DivideByZeroException and in the aspx view just added and invalid Model.Property. In both instances I got the Internal server error. I have done everything there is to be done as per documentation. I see a lot of other people having the same problem and not being able to solve it too. Is this a bug in MVC 3?

推荐答案

我想我已经想通了什么是真正的问题。我的主网页指数是在一个母版页。我加了相同的母版页中散发出来的Visual Studio框的默认错误页面,它为我工作。

I think I have figured out what really was the problem. My main Home page index was in a master page. I added the same master page to the default error page that comes out of the box with Visual Studio and it worked for me.

文档需要指出的更清楚这一重要要求,...如果它确实是其中之一。

The documentation needs to point out more clearly this important requirement,... if it indeed is one.

另一项惊人的启示是,你不需要用 [的HandleError] 属性来装饰你的控制器类。它的工作原理没有这种以及默认的错误观点。如果你想为你的操作或者控制器特定的自定义视图,你可以提供该属性。
像这样:

Another amazing revelation is that you don't need to decorate your controller classes with the [HandleError] attribute. It works without that as well for the default Error view. You may provide that attribute if you want a specific custom view for your action or controller.Like so:

[HandleError(View = "CustomError")]

...其中CustomError.aspx是无论是对视图或视图 - 控制器文件夹本身的共享文件夹只是一个普通的ASPX视图页面。

...where CustomError.aspx is just another plain aspx view page in either the shared folder for the View or in the View-Controller folder itself.

有没有人有这个工作,而不把错误页面,母版页,在抛出错误的主调用页面是在母版页?

Has anyone got this working without putting the error pages in a master page, where the main calling page that throws the error is in a master page?

这篇关于不显示自定义错误页asp.net的MVC的ErrorHandler的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-29 03:35