首页 > 解决方案 > 将网络核心 API 发布到 Azure 的问题

问题描述

我有一个 net core 3.1 REST API,我想将它发布到 Azure。我首先关注这篇文章: https ://docs.microsoft.com/en-us/aspnet/core/tutorials/publish-to-azure-api-management-using-vs?view=aspnetcore-5.0

当我添加 Swagger 时,我在安装 Swashbuckle.AspNetCore 包的第 3 版后遇到了一般错误“HTTP ERROR 550.30”的问题。当我安装最后一个版本时,API 再次在本地工作,但我无法将其发布到 Azure,因为 swagger 无法制作 swagger JSON 文件。我尝试了许多来自 GitHub 的建议,但没有任何效果!注意:如果我从库中移至版本 3.0.0,我可以发布 API,但会再次以“HTTP ERROR 550.30”结束

最后,我今天遇到了一个不同的错误,即使我没有更改代码上的任何内容:'Web 部署任务失败。(Web Deploy 无法修改目标上的文件“BuildingRestAPI.dll”,因为它被外部进程锁定。为了使发布操作成功,您可能需要重新启动应用程序以释放锁定或使用 AppOffline .Net 应用程序在下次发布尝试时的规则处理程序。在http://go.microsoft.com/fwlink/?LinkId=221672#ERROR_FILE_IN_USE了解更多信息。'

我会学徒任何帮助,因为我的任务时间不多了,我已经在这个问题上浪费了三天时间提前谢谢你

标签: asp.net-coreazure-web-app-service

解决方案


你确定你收到了HTTP ERROR 550.30吗?因为我认为它应该是一个HTTP ERROR 500.30.

我遵循了您发布的这篇文章,并使用版本 3 和最新的Swashbuckle.AspNetCore软件包测试了代码。使用最新版本时,我的 api 应用程序在本地和 Azure 上都运行良好,我可以Swagger.json通过这些 api 看到文件:

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();
            });
        }
    }
}
  1. 将包版本更新Swashbuckle.AspNetCore到更高版本,例如5.0.0,避免与最新版本的一些未知问题,看看它是否在本地工作。
  2. 当它在本地运行良好时,您可以再次发布,如果仍然出现错误,请使用kudu上的日志进行诊断。

推荐阅读