如何在netcore2.1中使用区域配置swagger?

时间:2018-08-22 01:45:04

标签: asp.net-core swagger area

我正在使用dotnet core 2.1为我的应用程序构建Restful API。我想用 大摇大摆地可视化我的webapi,但是当我们使用an area时,它会失败。有人可以告诉我如何用区域配置摇摇欲坠吗?非常感谢!

1 个答案:

答案 0 :(得分:0)

用路由属性装饰控制器

[Route("AREA/CONTROLLER")]

在Startup.cs

// Enable middleware to serve generated Swagger as a JSON endpoint.

app.UseSwagger();

// Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.),
// specifying the Swagger JSON endpoint.

app.UseSwaggerUI(c =>
{
    c.SwaggerEndpoint("/swagger/v1/swagger.json", "MovieRank V1");
    c.RoutePrefix = string.Empty;
});

app.UseMvc(routes =>
{
    routes.MapRoute(
        name: "areas",
        template: "{area:exists}/{controller=Home}/{action=Index}/{id?}"
    );
});