How to use Swagger as Welcome Page of IAppBuilder in WebAPI

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

    Ok, here is one way of doing it. Add a new MVC controller (Not Web API) e.g HomeController and in the Index action add the following code:

    using System.Web.Mvc;
    
    namespace Kids.Math.Api.Controllers
    {
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            return new RedirectResult("~/swagger/ui/index");
        }
    
    
    }
    

    }

    Also, make sure your route config has the follow (Note, by default it already does)

            public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
    
            routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
            );
        }
    

提交回复
热议问题