2

I followed this tutorial, but I am still receiving the ASP.NET screen that says to turn on Errors do this, or to show custom error page do this.

I have registered the HandleErrorAttribute and added the <customErrors mode="On" /> in web.config. The attribute is sitting directly on the line before the Controller class signature.

Am I still missing something?

EDIT

I removed the attribute from the class as you suggested, and this was the result. Nothing special going on I don't think.

web.config

</appSettings>
  <system.web>
    <customErrors mode="On" />
    <compilation debug="true" targetFramework="4.0">
      <assemblies>

Global.asax

public static void RegisterGlobalFilters(GlobalFilterCollection filters)
        {
            filters.Add(new HandleErrorAttribute());
        }

        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                "Default", // Route name
                "{controller}/{action}/{id}", // URL with parameters
                new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
            );

        }

        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);

Error*

Server Error in '/' Application.
Runtime Error
Description: An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed.

Details: To enable the details of this specific error message to be viewable on the local server machine, please create a <customErrors> tag within a "web.config" configuration file located in the root directory of the current web application. This <customErrors> tag should then have its "mode" attribute set to "RemoteOnly". To enable the details to be viewable on remote machines, please set "mode" to "Off".

<!-- Web.Config Configuration File -->

<configuration>
    <system.web>
        <customErrors mode="RemoteOnly"/>
    </system.web>
</configuration>


Notes: The current error page you are seeing can be replaced by a custom error page by modifying the "defaultRedirect" attribute of the application's <customErrors> configuration tag to point to a custom error page URL.

<!-- Web.Config Configuration File -->

<configuration>
    <system.web>
        <customErrors mode="On" defaultRedirect="mycustompage.htm"/>
    </system.web>
</configuration>
bdparrish
  • 3,216
  • 3
  • 37
  • 58
  • 1
    What kind of error are yhou getting? Some errors are not handled by default when using the attribute. – Erik Funkenbusch Oct 16 '11 at 14:43
  • I was testing it with the DivideByZeroException as the example showed. – bdparrish Oct 16 '11 at 15:47
  • I don't understand what you mean by the attribute is sitting on th eline before the controller class signature. If you're using a golobal filter, you don't need the attribute on the class. Show us your code in global.asax (both the Application_Start() and RegisterGlobalFilters) and the relevant part of your web.config. – Erik Funkenbusch Oct 16 '11 at 16:00
  • @MystereMan, see edits above. – bdparrish Oct 16 '11 at 20:05

2 Answers2

1

If you wish to see a custom error page (one that you design yourself) then you need to actually create the page and refer to in in the customErrors element;

<customErrors defaultRedirect="GenericError.htm" mode="On" />

In the example above, you would create the GernericError.htm page in your web application. This will be displayed if there is an error.

If you want to see details about the actual exception being thrown, then you need to set the mode to mode="Off" or mode="RemoteOnly"

Also, make sure that you are running the right version of asp.net (i.e. asp.net 4.0) in IIS for your application, otherwise your web.config file may not be parsed correctly, leading to this page.

Matt Tew
  • 1,581
  • 1
  • 9
  • 15
  • Sorry, didn't look at the tutorial first, to see what you were trying to do. So, the question now would be if the MVC application shows any view correctly at all? – Matt Tew Oct 16 '11 at 21:15
  • All other views are showing correctly. And I am sure the error view would show correctly, but it isn't making it to that point – bdparrish Oct 17 '11 at 14:15
0

Here is a conversation about Razor custom-views that works for me and many others. Test it. May be helpful to you too.

Community
  • 1
  • 1
amiry jd
  • 27,021
  • 30
  • 116
  • 215