Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET WebAPI default landing page

Tags:

I've created a RESTful web service using ASP.NET WebApi v2 and I'm using Swashbuckle to generate swagger UI for API documentation.

All API calls are under http://localhost/api/ and the swagger UI page is at http://localhost/browser/index (the 'browser' part is configurable).

Browsing to http://localhost/ however will land on a empty page, so my question is is it possible to route http://localhost/ to http://localhost/browser/index so the user will be able to see the API documentation just by visiting the base uri.

One solution I can think of is to use a physical file system and create a static html page which does a meta fresh to redirect to the landing page I want, but I guess there must be a better way of doing this…

like image 236
Godsent Avatar asked Nov 24 '15 10:11

Godsent


People also ask

What is the default path of Web API?

The default route template for Web API is "api/{controller}/{id}". In this template, "api" is a literal path segment, and {controller} and {id} are placeholder variables.

What is default return type of Web API?

By default Web API returns result in XML format.

How do I find my Web API URL?

You can easily find the Web API addresses and version number for your deployment in the Customer Engagement web application by navigating to Settings > Customization > Developer Resources.


1 Answers

Change the route configuration RouteConfig.cs.

Instead of the default setting:

routes.MapRoute(     name: "Default",     url: "{controller}/{action}/{id}",     defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } ); 

Change it to point at swagger:

routes.MapRoute(     name: "Default",     url: "{controller}/{action}/{id}",     defaults: new { controller = "Browser", action = "Index", id = UrlParameter.Optional } ); 

Make sure you update RouteConfig.cs and not WebApiConfig.cs.

like image 169
Karl Gjertsen Avatar answered Sep 24 '22 14:09

Karl Gjertsen