我正在使用一个简单的.net核心API,但发现无法解释的奇怪行为:
API可以正常工作到一个点(40-50个调用),在该点每个调用都会失败,并在超时后返回HTTP错误502.3-错误的网关。
经过一些调查,我发现删除配置文件中的ASPNETCORE_ENVIRONMENT(设置为开发)时不会出现此行为。
因此,具体来说,哪些差异意味着我的ASPNETCORE_ENVIRONMENT设置为“开发”?我如何设法使其在此设置下正常工作?
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)
{
var dbString = Configuration["Database:ConnectionString"];
services.AddScoped<ISearchEngineRepository, SearchEngineRepository>();
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
services.AddDbContext<VvpDbContext>(options => options.UseSqlServer(dbString), ServiceLifetime.Transient);
services.AddSingleton(Configuration);
services.AddCors();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseCors(options => options.WithOrigins("http://localhost:4200").AllowAnyMethod());
}
else
{
app.UseHsts();
}
app.UseMvc();
}
}