Multiple actions were found that match the request

Hi,

I had written a new HTTPGet method and it worked well. After sometime, I got a requirement to write one more new HTTPGet method and I had troubles. The code started failing by throwing the below error.

“Multiple actions were found that match the request”

After some search I was able to identify the issue as we have to specify which action(method) we need send your HTTP request. For fixing it, we have to add routes in the WebApiConfig in the below order. The order plays important rule here. 

        public static void Register(HttpConfiguration config)
        {
            // Web API configuration and services
            // Web API routes
            config.MapHttpAttributeRoutes();
            config.Routes.MapHttpRoute(
            name: “ControllerAndActionOnly”,
            routeTemplate: “api/{controller}/{action}”,
            defaults: new { },
            constraints: new { action = @”^[a-zA-Z]+([\s][a-zA-Z]+)*$” });
            config.Routes.MapHttpRoute(
                name: “DefaultApi”,
                routeTemplate: “api/{controller}/{id}”,
                defaults: new { id = RouteParameter.Optional }
            );

        }

Hope this helps.


Happy Coding

Gopinath

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s