ASP.NET WebAPI default landing page

荒凉一梦 提交于 2019-12-04 10:08:02

问题


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…


回答1:


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.



来源:https://stackoverflow.com/questions/33891721/asp-net-webapi-default-landing-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!