C# 容器实例的Azure中未启用访问招摇过市
我有一个webapi在启用了开放api的Auzure容器实例中运行。但我不能接近斯威格 我可以导航到控制器并查看输出:(works) 但我无法访问此页面: 如何在Auzure容器实例中使用swagger 这是我的Startup.cs:C# 容器实例的Azure中未启用访问招摇过市,c#,azure,docker,azure-devops,swagger,C#,Azure,Docker,Azure Devops,Swagger,我有一个webapi在启用了开放api的Auzure容器实例中运行。但我不能接近斯威格 我可以导航到控制器并查看输出:(works) 但我无法访问此页面: 如何在Auzure容器实例中使用swagger 这是我的Startup.cs: public class Startup { public Startup(IConfiguration configuration) { Configuration = configuration; } pu
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers();
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo { Title = "WebApplication2", Version = "v1" });
});
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseSwagger();
app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "WebApplication2 v1"));
}
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}
}
当我在本地启动应用程序时,它会起作用。添加答案以便对其他人有用 如果代码中缺少配置部分,请将
UseSwagger
移到外部,以便它在其他环境中工作
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseSwagger();
app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "WebApplication2 v1"));
你能提供你的创业计划吗?应用程序。您是否使用了SwaggerUI和AddSwaggerGen调用?你能在本地主机上访问swagger吗?@SeeSharp我更新了我的问题:)@SeeSharp:我将尝试删除if(env.IsDevelopment)…尝试将swagger移到if(env.IsDevelopment())之外,或者检查你是否打开了dev envazure@SeeSharp:是的,我删除了if语句,它成功了。