ASP.NET WebAPI 默认登陆页面
ASP.NET WebAPI default landing page
我已经使用 ASP.NET WebApi v2 创建了一个 RESTful 网络服务,我正在使用 Swashbuckle 为 API 文档生成 swagger UI .
所有 API 调用都在 http://localhost/api/ and the swagger UI page is at http://localhost/browser/index 下('browser' 部分是可配置的)。
浏览到 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 这样用户就可以通过访问基本 uri 来查看 API 文档。
我能想到的一个解决方案是使用物理文件系统并创建静态 html 页面,该页面执行元新鲜以重定向到我想要的登录页面,但我想一定有更好的方法这样做的方式...
更改路由配置RouteConfig.cs
。
而不是默认设置:
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
将其更改为指向 swagger:
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Browser", action = "Index", id = UrlParameter.Optional }
);
确保更新 RouteConfig.cs
而不是 WebApiConfig.cs
。
我已经使用 ASP.NET WebApi v2 创建了一个 RESTful 网络服务,我正在使用 Swashbuckle 为 API 文档生成 swagger UI .
所有 API 调用都在 http://localhost/api/ and the swagger UI page is at http://localhost/browser/index 下('browser' 部分是可配置的)。
浏览到 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 这样用户就可以通过访问基本 uri 来查看 API 文档。
我能想到的一个解决方案是使用物理文件系统并创建静态 html 页面,该页面执行元新鲜以重定向到我想要的登录页面,但我想一定有更好的方法这样做的方式...
更改路由配置RouteConfig.cs
。
而不是默认设置:
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
将其更改为指向 swagger:
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Browser", action = "Index", id = UrlParameter.Optional }
);
确保更新 RouteConfig.cs
而不是 WebApiConfig.cs
。