Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8702133
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:34:33+00:00 2026-06-13T02:34:33+00:00

I am migrating a project that was developed using WebApi Preview 5 (when it

  • 0

I am migrating a project that was developed using WebApi Preview 5 (when it was part of WCF) to the final release of WebApi (part of MVC4). There is a document describing the process but it is extremely simplistic and doesn’t cover most of the issues.

Now one of the issues I am facing is that a GlobalErrorHandler was created by inheriting from HttpErrorHandler and then overriding OnTryProvideResponse and that was used to hook error handling with Elmah. Now that was registered on AppStart with a line like this:

var configuration = new WebApiConfiguration();
//some other configuration for security and CreateInstance
configuration.ErrorHandlers = 
(handlers, endpoint, description) => handlers.Add(new GlobalErrorHandler())
};
//then some registration
RouteTable.Routes.MapServiceRoute<SomeObject>("routeName", configuration);

and then mapping different route to this configuration. All this code doesn’t work in the new world of MVC4 WebApi, it seems like there is a conflict between HttpErrorHandler and it can’t even implement its members properly.

Now I’ve seen general posts about how to register Elmah with WebApi but I am trying to stick to the original code as much as possible and I am assuming – may be I am wrong – that there is a direct equivalent to what Microsoft had in the Preview version and what they released in the final one. So my questions:

  1. What is the equivalent of this Global Error handling registation in ASP.NET MVC4 WebApi?
  2. Do I need to do the configuration the same way it is done here (default webapi samples project doesn’t seem to have similar code)
  3. What is the equivalent of that route registration line of code: RouteTable.Routes.MapServiceRoute(“routeName”, configuration);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T02:34:34+00:00Added an answer on June 13, 2026 at 2:34 am

    If you create a quick one-off WebApi MVC project in Visual Studio you will see an App_Start folder which contains some classes which have static methods for handling the registration, specifically:

    • FilterConfig.cs
    • WebApiConfig.cs

    WebApi Config is where you need to register routes etc…

    public static class WebApiConfig
    {
        public static void Register(HttpConfiguration config)
        {
            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );
        }
    }
    

    Filter config is what you need to handle your global errors… Filter config has a default error handler attribute added which you can swap out or out

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

    Global.asax calls these static registration scripts like so:

     protected void Application_Start()
        {
    
            WebApiConfig.Register(GlobalConfiguration.Configuration);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
    
        }
    

    In regard to Elmah it appears simplying including the Nuget package will register it…

    Look for the package Elmah.Mvc

    PM> Install-Package Elmah.MVC
    

    it used to be like this How to get ELMAH to work with ASP.NET MVC [HandleError] attribute? but now according to this blog it has changed:

    HandleErrorAttribute inside If you tried to use ELMAH in ASP.NET MVC,
    you are probably implemented your own HandleErrorAttribute, as it’s
    shown in this example. You no longer need to apply this custom code
    with Elmah.MVC. As soon you installed package, so can safely remove
    your HandleError attribute, since it’s already included into package.

    This now appears to register itself in the Web.Config as a managedHandler so your code does not need to reference Elmah directly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently migrating a project that is using Spring MVC without annotations to Spring
I have an open source project that is primarily developed using MonoDevelop. I went
We have a web application that runs on IIS using .NET 2.0 developed and
We're migrating from Perforce to GIT. In perforce, there were some files that I'd
I'm working on a project that is currently migrating from Apache Tomcat 6 to
I'm working on migrating a project which is very JSP-centric to using Velocity. In
I am a university student working on a research project that involves migrating a
I have these two file in my project that I am migrating from php.
I have a Flash builder project that I am migrating from SDK 4.1.0 to
I work on some project that is migrating from vb6 to web (asp.net). I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.