azure - .NET Core API 无法在 Azure 应用服务上运行 - 您正在查找的资源已被删除、更名或暂时不可用

标签 azure api .net-core

我已将 API 部署到 Azure 应用服务并收到错误:

您要查找的资源已被删除、更名或暂时不可用。

任何时候我尝试访问 API 中当前唯一操作的端点。所有文件都已正确部署在 wwwroot 文件夹中,如果我输入 url/filename(其中 url 是基本 url,文件名是文件夹中的任何文件),我就可以下载该文件。该 API 在本地运行时有效,点击操作会返回预期的 json 结果。

运行跟踪给出了相当通用的结果:

系统.NullReferenceException 2 你调用的对象是空的。 堆栈跟踪 1 mscorlib!System.Diagnostics.Tracing.EventSource.SendCommand mscorlib!System.Diagnostics.Tracing.EventSource+OverideEventProvider.OnControllerCommand mscorlib!System.Diagnostics.Tracing.EventProvider.EtwEnableCallBack mscorlib!dynamicClass.IL_STUB_ReversePInvoke

路由配置正确(因为它在本地工作) - 该错误意味着缺少相关文件,但是检查 Kudu 中的文件夹显示文件与 bin 文件夹的内容匹配。关于这里出了什么问题有什么想法吗?或者如何确定丢失的资源是什么?感谢您的阅读。

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.AddLogging(logging =>
        {
            logging.AddConsole();
            logging.AddDebug();
        });
        services.AddDbContext<hidden>(options => options.UseSqlServer(Configuration.GetConnectionString("hidden")));
        services.AddScoped<DbContext, hidden>();
        services.AddScoped(typeof(IQuery<>), typeof(NoTrackingQuery<>));
        services.AddScoped(typeof(IQuery<,>), typeof(NoTrackingQuery<,>));
        services.AddSwaggerGen(c =>
        {
            c.SwaggerDoc("v1", new OpenApiInfo { Title = "Hidden", 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)
    {
        // Expose logging where DI cannot be used
        var loggerFactory = app.ApplicationServices.GetRequiredService<ILoggerFactory>();
        LogManager.SetLogger(loggerFactory);

        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
            app.UseSwagger();
            app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "Hidden v1"));
        }

        app.UseHttpsRedirection();

        app.UseRouting();

        app.UseAuthorization();

        app.UseEndpoints(endpoints =>
        {
            endpoints.MapControllers();
        });
    }
}

  [ApiController]
[Route("[controller]")]
public class WidgetController : ControllerBase
{
    private readonly IQuery<Category> _categories;

    public WidgetController(IQuery<Widget> widgets)
    {
        _widgets = widgets;
    }

    [HttpGet]
    public IEnumerable<Widget> Get()
    {
        return _widgets.QueryAll();
    }
}

最佳答案

当您可以在本地运行解决方案,而无法在云端运行它时,则意味着您配置错误。

查看错误消息,我怀疑日志记录设置不正确。确保将所有必需/使用的设置放入 Application Settings 中或Connection Strings .

关于azure - .NET Core API 无法在 Azure 应用服务上运行 - 您正在查找的资源已被删除、更名或暂时不可用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66997429/

相关文章:

c# - 从 .net core 2.2 迁移到 3.1 后无法上传文件

asp.net - httpErrors 配置部分在 Windows Azure 中不起作用

azure - 使用 Windows Azure 服务总线进行消息路由

php - 构建 REST api 时如何处理查询字符串中参数的动态数量?

javascript - Google map API - 'google' 未定义 - MVC5 javascript

Azure 存储文件 "Authentication scheme Bearer is not supported." "AuthenticationFailed"

Azure 管道不会从具有单个 azure-pipelines.yml 文件的分支触发

Azure 门户 - 添加角色组无法正常工作

Azure Pipelines .net core 3.1 库以及对其他库的引用如何创建一个 nuget 包

c# - rzc 发现退出,代码 -2147450743