How to use Swagger as Welcome Page of IAppBuilder in WebAPI

后端 未结 12 1576
遥遥无期
遥遥无期 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:48

    In the Startup.cs file in the Configuration(IAppBuilder app) method I used this line of code to cause it to redirect on load to the swagger welcome page.

    app.Run(async context => { 
        context.Response.Redirect("swagger/ui/index"); 
    }); 
    

    So the full method I am using is as follows

    [assembly: OwinStartup(typeof(AtlasAuthorizationServer.Startup))]
    namespace AtlasAuthorizationServer
    {
        public partial class Startup
        {
            public void Configuration(IAppBuilder app)
            {
                ConfigureAuth(app);
    
                HttpConfiguration config = new HttpConfiguration();
                WebApiConfig.Register(config);
                app.UseWebApi(config);
    
                app.Run(async context => {
                    context.Response.Redirect("swagger/ui/index");
                });
            }
        }
    }
    

    Note that this is going to cause a green warning in visual studio. I am sure there is some way to mimic this as asynchronous with an await call in the function.

提交回复
热议问题