Click here to Skip to main content
15,887,476 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am a newbie to webAPI. I have an existing webAPI project which i need to run/debug.This project used Attribute based routing for each action method.In RouteConfig.cs file they have {controller}/{action} as URL parameter in MapRoute method(Please note that they have removed the "api/" part from there).But still I'm not able to call the webservices like this ->"http://localhost/{controller}/{action}".However, i am able to call them after prefixing "api/" before controller name i.e. "http://localhost/api/{controller}/{action}".

Can someone help me to figure out where else this routing configuration may be defined?

Thanks

What I have tried:

Changing routing configurations
Posted
Updated 24-Apr-17 12:32pm
Comments
Afzaal Ahmad Zeeshan 24-Apr-17 10:43am    
Because your routing is still configured to accept the ApiController derived controllers at "/api/" location, not anywhere else. Check the Web API routing not the default MVC routing.

1 solution

Web API configuration isn't in your RouteConfig.cs, rather your WebApiConfig.cs file. Here you will find the prefix of api/.

C#
public static void Register(HttpConfiguration config)
        {
            // Web API configuration and services

            // Web API routes
            config.MapHttpAttributeRoutes();

            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );
        }


You'll need the prefix (api/) of some sort as there will be confusion whether its an attribute route or a normal MVC type route.

But i think the primary source of your issue is you need to be looking in the WebApiConfig.cs file.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900