我使用的是ASP.NET Core 6和NSwag.AspNetCore v13.20.0。
我应该如何配置app.UseSwaggerUi3();
,以使默认的swagger页面在该url https://url/prefix/swagger/index.html
而不是此https://url/swagger/index.html
中打开?
在斯威格前面加个前缀
请注意,UseSwaggerUi
已过时
ConfigureServices
public void ConfigureServices(IServiceCollection services)
{
_logger.Info("ConfigureServices starting...");
try
{
services.AddControllers(x =>
{
x.OutputFormatters.RemoveType<HttpNoContentOutputFormatter>();
})
.AddNewtonsoftJson(x =>
{
x.SerializerSettings.TypeNameHandling = Newtonsoft.Json.TypeNameHandling.Objects;
});
services.AddTypeSignatureSHA256();
services.AddHttpClient(nameof(HttpClient)).AddPolicyHandler(GetHttpRetryPolicy());
services.Configure<IISServerOptions>(options => options.AutomaticAuthentication = false);
services.AddSwaggerDocument(settings =>
{
settings.Title = "xxx Api";
});
_logger.Info("ConfigureServices ended");
}
catch (Exception ex)
{
_logger.Error(ex, string.Empty);
throw;
}
}
字符串
配置
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IHostApplicationLifetime appLifeTime)
{
_logger.Info("Configure starting...");
try
{
RegisterApplicationShutdown(appLifeTime);
if (env.IsDevelopment())
app.UseDeveloperExceptionPage();
app.UseRouting();
app.UseMiddleware<ExceptionsMiddleware>();
app.UseMiddleware<HealthChecksUIMiddleware>();
app.UseAppMetricsPrometheus(new AppMetricsPrometheusSettings { UseSystemUsageCollector = true });
app.UseMiddleware<AppMetricsRequestsMiddleware>();
app.UseMiddleware<RequestLoggingMiddleware>();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
app.UseOpenApi();
app.UseSwaggerUi3();
_logger.Info("Configure ended");
}
catch (Exception ex)
{
_logger.Error(ex, string.Empty);
throw;
}
}
型
2条答案
按热度按时间l5tcr1uw1#
这适用于NSwag。AspNetCore
字符串
你可以试试这个:
型
在launchsettings.json中,您可能需要更改launchUrl
x1c 0d1x的数据
测试
的
kcugc4gi2#
请访问https://github.com/RSuter/NSwag/wiki/AspNetCore-Middleware#hosting-as-an-iis-virtual-application
如果它不为你工作,联系我。