0

I have an MVC4 project with many controllers. I added an API controller called BatchDetailsController in the root directory of the project.

I also created a WebApiConfig class as below:

 public static void Register(HttpConfiguration config)
        {
            // Web API configuration and services
            // Configure Web API to use only bearer token authentication.

            // Web API routes
            config.MapHttpAttributeRoutes();

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

I also invoke the above register method from global.asax as

  WebApiConfig.Register(GlobalConfiguration.Configuration);

in Application_Start

Now I have tried to access the controller by using then URLs
/BatchDetails
/api/BatchDetails
/BatchDetails/Get
/api/BatchDetails/Get

All of them return 404

What is the URL I need to use in this case?

1 Answer 1

0

for example when using visual studio to debug/host the project the url would be http://localhost:port/api/BatchDetals/{method}

Right click on the project and see if IIS express is selected and note the port number. The project should come up via run/f5 in visual studio at the Project URL.

If not I would re-install IIS8 express.

Visual Studio Project Settings

Sign up to request clarification or add additional context in comments.

3 Comments

where is the project hosted (visual studio cassini?) IIS express other?
Add HttpGet attribute on BatchDetails method and try localhost:50130/api/BatchDetails

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.