ASP.NET WebAPI默认登录页面 [英] ASP.NET WebAPI default landing page

查看:695
本文介绍了ASP.NET WebAPI默认登录页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用ASP.NET WebApi v2创建了RESTful Web服务,并且正在使用 Swashbuckle 生成用于API文档的swagger UI.

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

所有API调用均在 http://localhost/api/下,而庄重的UI页面位于 http://localhost/browser/index (浏览器"部分是可配置的).

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

浏览到 http://localhost/却会进入空白页面,所以我的问题是是否可以路由 http://localhost/ http://localhost/browser/index ,因此用户只需访问基本uri就可以查看API文档.

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.

我能想到的一种解决方案是使用物理文件系统并创建一个静态html页面,该页面会进行元刷新以重定向到我想要的登录页面,但是我想必须有一种更好的方法...

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…

推荐答案

更改路由配置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.

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

这篇关于ASP.NET WebAPI默认登录页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆