如何将 Swagger 设置为默认起始页? [英] How to set Swagger as default start page?

查看:156
本文介绍了如何将 Swagger 设置为默认起始页?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将 Swagger 设置为 ABP 模板中的默认起始页而不是 /Account/Login?

How do I set Swagger as the default start page in ABP template instead of /Account/Login?

我使用的是 ASP.NET MVC 5.x + Angular 1.x.

I'm using ASP.NET MVC 5.x + Angular 1.x.

当前代码:

public static void RegisterRoutes(RouteCollection routes)
{
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

    //ASP.NET Web API Route Config
    routes.MapHttpRoute(
        name: "swagger_root",
        routeTemplate: "",
        defaults: null,
        constraints: null,
        handler: new RedirectHandler((message => message.RequestUri.ToString()), "swagger"));

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

一切都还好,除了 Module Zero 的 "api/Account/Authenticate" 请求已经中断,显示:

Everything is still working fine, except Module Zero's "api/Account/Authenticate" request that has broken, showing:

找不到资源.

推荐答案

this 中添加路由https://github.com/aspnetboilerplate/module-zero-template/blob/aaf24a1b0b18dc11e9aba7b5101d98d1fa621b3f/src/AbpCompanyName.AbpProjectName.WebSpaAngular/App_Start/RouteConfig.cs#L23" Route rel="noreferrs">as在这里评论:

Add this routing in RouteConfig.cs as commented out here:

public static void RegisterRoutes(RouteCollection routes)
{
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

    //ASP.NET Web API Route Config
    routes.MapHttpRoute(
        name: "DefaultApi",
        routeTemplate: "api/{controller}/{id}",
        defaults: new { id = RouteParameter.Optional }
        );

    // Set Swagger as default start page
    /*
    routes.MapHttpRoute(
        name: "swagger_root",
        routeTemplate: "",
        defaults: null,
        constraints: null,
        handler: new RedirectHandler((message => message.RequestUri.ToString()), "swagger"));
    */

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

这篇关于如何将 Swagger 设置为默认起始页?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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