bdparrish
bdparrish

Reputation: 2764

Showing built-in Error View for MVC 3

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>

Upvotes: 2

Views: 2078

Answers (2)

Matt Tew
Matt Tew

Reputation: 1621

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.

Upvotes: 1

amiry jd
amiry jd

Reputation: 27585

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

Upvotes: 0

Related Questions