0

I have a net web API set up. The URL I want to route to is https://localhost:44378, but Web API forces me to use https://localhost:44378/api/status.

How do I set up a default so if any traffic comes in at https://localhost:44378? redirects to the same code as https://localhost:44378/api/status?

I have tried to use * as the routing default

1 Answer 1

1

You should have a WebApiConfig.cs in the App_Start folder of your application.

    public static class WebApiConfig
    {
        public static void Register(HttpConfiguration config)
        {

            .......

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

Try removing "api" from the routeTemplate.

For .net core web api, the default is a Route attribute in the controller.

If I use the template to create a Web Api in .Core it gives me a ValuesController.

namespace CoreApi.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class ValuesController : ControllerBase
    {

Just change the route attribute and remove api

        [Route("[controller]")]
Sign up to request clarification or add additional context in comments.

6 Comments

Hi by default web api .net core has code app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller}/{action}/{id?}" //defaults: new { controller = "TravelPortSync", action = "FullSync" } ); });
@vaughn, I've edited my answer. Does that work for you?
hi that worked if my url is localhost:44378/api is there a way to make it work for localhost:44378
Yes. You just remove the api from the Route as shown.
Hi I got them to change the url to the correct path. is there a way to log any 404 or 400 responses to view what is being sent to the web api?
|

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.