How to use Swagger as Welcome Page of IAppBuilder in WebAPI

后端 未结 12 1559
遥遥无期
遥遥无期 2020-12-24 05:59

I try to use Swagger with Microsoft WebAPI 2.

For the moment, I\'ve the following call in a method.

appBuilder
   .ConfigureOAuth()
   .UseWebApi(con         


        
12条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-24 07:00

    I got this working how I wanted by adding a route in RouteConfig.cs like so:

        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
    
            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 }
            );
        }
    

    See this code from swashbuckle to see what's going on: https://github.com/domaindrivendev/Swashbuckle/blob/master/Swashbuckle.Core/Application/RedirectHandler.cs

提交回复
热议问题