asp.net-core - 将网络核心 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了解更多信息。'
我会学徒任何帮助,因为我的任务时间不多了,我已经在这个问题上浪费了三天时间提前谢谢你
解决方案
你确定你收到了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();
});
}
}
}
- 将包版本更新
Swashbuckle.AspNetCore
到更高版本,例如5.0.0
,避免与最新版本的一些未知问题,看看它是否在本地工作。 - 当它在本地运行良好时,您可以再次发布,如果仍然出现错误,请使用kudu上的日志进行诊断。
推荐阅读
- ajax - 如何将 formcollection 转换为模型 ins ASP.NET MVC
- c# - 将 IAsyncEnumerable 与 Dapper 一起使用
- flutter - 有没有办法在 Flutter 中打开抽屉后立即隐藏状态栏?
- firebase - 颤振:CachedNetworkImage 不缓存图像
- ios - 设置根视图控制器时,我可以保留模态呈现的视图控制器吗?
- javascript - 当 map 函数在代码中时,它返回 undefined,当 console.log 它返回一个空对象和一个数据。我只想要数据
- api - CQRS 和 DDD:文件上传
- button - nattable 中的按钮覆盖了我桌子的一半,有人可以解释为什么吗?
- javascript - 如何使以下代码与 IE 一起使用
- c# - ASP.NET Core 3.1 中的图像提供程序