【发布时间】: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();
}
}
【问题讨论】: