【问题标题】:Problem with publishg net core API into Azure将网络核心 API 发布到 Azure 的问题
【发布时间】:2021-07-20 07:53:21
【问题描述】:
【问题讨论】:
标签:
asp.net-core
azure-web-app-service
【解决方案1】:
您确定收到HTTP ERROR 550.30 吗?因为我认为它应该是HTTP ERROR 500.30。
我关注了您发布的 article 并使用版本 3 和最新的 Swashbuckle.AspNetCore 包测试了代码。使用最新版本时,我的 api 应用程序在本地和 Azure 上都运行良好,我可以通过这些 api 看到 Swagger.json 文件:
https://{your-website}/swagger/v1/swagger.json
https://{your-website}/swagger/index.html
使用 3.0.0 版本时,由于不兼容的问题,我的项目无法发布。看来我的项目使用了高.net core版本,Swashbuckle.AspNetCore包版本太低,无法支持。
这是我的Startup.cs:
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using NLog.Extensions.Logging;
namespace TodoApi
{
public class Startup
{
private readonly string swaggerBasePath = "api/app";
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();
services.AddLogging(builder =>
{
builder.SetMinimumLevel(LogLevel.Information);
builder.AddNLog("nlog.config");
});
}
// 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.UseHttpsRedirection();
app.UseSwagger();
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}
}
}
- 更新
Swashbuckle.AspNetCore包版本到更高版本,比如5.0.0,避免最新版本出现一些未知问题,看看本地能不能用。
- 当它在本地运行良好时,您可以再次发布,如果仍然出现错误,请使用 kudu 上的日志进行诊断。