【发布时间】:2023-04-04 10:17:01
【问题描述】:
当我使用 curl -I localhost:5100 验证它到达主页时,我在 Azure K8s 集群中部署了一个 ASP.net core swagger API,当我尝试 curl -I locolhost:5100/index.html i 时出现错误 404得到响应 200。
知道这是我的启动课程可能导致此问题的原因
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
var healthCheckOptions = new HealthCheckOptions
{
ResponseWriter = WriteReadinessResponse
};
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
endpoints.MapHealthChecks("/health/readiness", healthCheckOptions);
endpoints.MapHealthChecks("/health/liveness", new HealthCheckOptions()
{
Predicate = (_) => false
});
});
// enable swagger support
app.UseSwagger();
app.UseSwaggerUI(c =>
{
c.RoutePrefix = string.Empty;//all request to route [/] are being forward to index.html somehow
c.SwaggerEndpoint("/swagger/v1/swagger.json", "Demo API V1");
});
}
有没有办法解决这个问题?我喜欢 curl -I localhost:5100 时得到响应 200。
【问题讨论】:
标签: asp.net-core routes swagger