【问题标题】:.NET Core API will not work on Azure App Service-The resource you are looking for has been removed,had its name changed,or is temporarily unavailable.NET Core API 无法在 Azure 应用服务上运行 - 您要查找的资源已被删除、名称已更改或暂时不可用
【发布时间】:2021-07-03 22:28:16
【问题描述】:

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

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

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

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

System.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();
    }
}

【问题讨论】:

    标签: azure api .net-core


    【解决方案1】:

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

    查看错误消息我怀疑 Logging 的设置没有到位。确保将所有必需/使用的设置放入 Application SettingsConnection Strings

    【讨论】:

      【解决方案2】:

      感谢 singhh-msft。您是对的,这是由于在构建管道中使用了不正确的发布任务造成的。更新为使用 dotnet Azure CLI publish 命令,问题已解决。

      【讨论】:

      • 您能否将我的答案标记为已接受? - 这将有助于其他社区成员。
      猜你喜欢
      • 2020-04-20
      • 1970-01-01
      • 2016-10-27
      • 1970-01-01
      • 2018-01-05
      • 2016-07-25
      • 2020-07-01
      • 2016-10-29
      • 1970-01-01
      相关资源
      最近更新 更多