ASP.NET WebAPI 默认登陆页面

2024-02-09

我已经使用 ASP.NET WebApi v2 创建了一个 RESTful Web 服务,并且正在使用虚张声势 https://github.com/domaindrivendev/Swashbuckle为 API 文档生成 swagger UI。

所有API调用都在http://localhost/api/ http://localhost/api/swagger UI 页面位于http://localhost/浏览器/索引 http://localhost/browser/index(“浏览器”部分是可配置的)。

正在浏览至http://本地主机/ http://localhost/但是会落在一个空白页面上,所以我的问题是是否可以路由http://本地主机/ http://localhost/ to 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 }
);

将其更改为指向 swagger:

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

确保你更新了RouteConfig.cs并不是WebApiConfig.cs.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

ASP.NET WebAPI 默认登陆页面 的相关文章

随机推荐