.net - ASPNETCORE_ENVIRONMENT 设置为“开发”以某种方式限制 API 调用
问题描述
我正在研究一个简单的 .net 核心 API,并注意到一个我无法解释的奇怪行为:
API 工作正常,直到每次调用失败并返回 HTTP 错误 502.3 - 超时后网关错误的点(40-50 次调用)。
经过一些调查,我发现当我删除配置文件中的 ASPNETCORE_ENVIRONMENT (设置为开发)时,这种行为没有出现。
那么,具体来说,哪些差异意味着我的 ASPNETCORE_ENVIRONMENT 设置为 Development?我怎样才能让它与这个设置一起工作?
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();
}
}
解决方案
推荐阅读
- php - 从 ZendFramework 3 调用存储过程
- javascript - react-native 将两个数组合二为一
- node.js - 使用 sinon 模拟连接池和测试 url 参数?
- javascript - 将javascript字符串转换为数组
- java - SpringBoot 2.0.4.RELEASE 中的 ResponseEntityExceptionHandler
- c# - 在 C# 中具有 IF 条件的睡眠线程
- vba - VBScript 允许在 Excel 文件中编辑并另存为
- android - Android:从左侧拉动 SwipeRefreshLayout 进行刷新
- javascript - 在chartjs的条形顶部添加图像
- linux - 如何在 ExecStop 或 ExecPostStop 中访问服务的返回码?