我已经使用ASP.NET WebApi v2创建了RESTful Web服务,并且正在使用Swashbuckle生成用于API文档的庞大UI。
所有API调用都位于http:// localhost / api /下,而庄重的UI页面位于http:// localhost / browser / index(“浏览器”部分是可配置的)。
浏览到http:// localhost /却会停留在一个空白页面上,因此我的问题是是否可以将http:// localhost /路由到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 }
);
将其更改为指向招摇:
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Browser", action = "Index", id = UrlParameter.Optional }
);
确保您更新RouteConfig.cs
而不是WebApiConfig.cs
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句