Asp.Net Core 3.0 WebApi 使用Swagger
2021-01-29 10:15
public void ConfigureServices(IServiceCollection services) { services.AddControllers(); services.AddRazorPages(); #region Swagger配置 services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new Microsoft.OpenApi.Models.OpenApiInfo { Title = "My API", Version = "v1" }); c.ResolveConflictingActions(apiDescriptions => apiDescriptions.First()); });
#endregion
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Latest);
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseRouting();
app.UseStaticFiles();//启动静态文件
app.UseAuthorization();
#region session配置
app.UseSession();
#endregion
#region Swagger配置
//启用中间件服务生成Swagger作为JSON终结点
app.UseSwagger();
//启用中间件服务对swagger-ui,指定Swagger JSON终结点
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
});
#endregion
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
endpoints.MapAreaControllerRoute(
name: "areas", "Admin",
pattern: "{area:exists}/{controller=Users}/{action=Index}/{id?}");
endpoints.MapRazorPages();
});
}
文章标题:Asp.Net Core 3.0 WebApi 使用Swagger
文章链接:http://soscw.com/index.php/essay/48643.html