I am working on asp.net web api. I am trying to set the default route for my project in global.asax file like,
localhost:45678/api/Products
But i didnt find any format similar to asp.net mvc route model like
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
It always redirects me to Home page(HomeController). please guide me.
Check your your RouteConfig
class in your App_Start
folder. You should see the default route below which you can change.
routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
EDIT
After reading your comments, I think the problem is not with your routes. I'm not sure why you would want to do it, but you just need to specify the Start URL for your project. Right click your web project - click Properties - click the Web tab - under Start Action select Start URL and enter http://localhost:45678/api/Products
in the box. Save your project and run again. It should start at the new location.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With