How to use Swagger as Welcome Page of IAppBuilder in WebAPI

后端 未结 12 1502
遥遥无期
遥遥无期 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 06:56

    I had similar problem and I solved it by customizing SwaggerUI url. This is my Configuration method:

    public void Configuration(IAppBuilder app)
    {
        var thisAssembly = typeof (Startup).Assembly;
    
        HttpConfiguration httpConfig = new HttpConfiguration();
    
        app.MapHttpAttributeRoutes();
        app.UseCors(CorsOptions.AllowAll);
        app.UseWebApi(httpConfig);
    
        httpConfig
            .EnableSwagger("api/{apiVersion}",c =>
            {
                c.IncludeXmlComments(string.Format(@"{0}\bin\Docs.xml", AppDomain.CurrentDomain.BaseDirectory));
                c.SingleApiVersion("v1", "My API");
            })
            .EnableSwaggerUi("{*assetPath}",c =>
            {
                c.CustomAsset("index", thisAssembly, "AspNetIdentity.WebApi.DocsAssets.index.html");
            });
    
        httpConfig.Routes.First(x => x.RouteTemplate == "{*assetPath}").Defaults["assetPath"] = "index";
    }
    

    This way when You go to localhost:44300 You'll get Swagger UI as startup page.

提交回复
热议问题