【发布时间】:2018-09-19 07:20:46
【问题描述】:
我有一个部署到 AWS ElasticBeanstalk 的 .NET Core MVC 应用程序。但是当我去应用程序时,我收到一条错误消息:
不应在已部署的应用程序中启用开发环境
- 在
launchsettings.json文件中我设置了ASPNETCORE_ENVIRONMENT's 值为Production。 - 当我使用 Visual Studio (AWS toolkit) 部署应用程序时,我将
Project build configuration的值设置为Release。 - 我还创建了带有名称的环境变量
ASPNETCORE_ENVIRONMENT和Production中的值EB Software Configuration。
我的launchSettings.json 文件如下所示:
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://DUMMY.us-west-2.elasticbeanstalk.com/",
"sslPort": 0
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "http://DUMMY.us-west-2.elasticbeanstalk.com/",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"AlacsWeb": {
"commandName": "Project",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "http://DUMMY.us-west-2.elasticbeanstalk.com/"
}
}
}
还有startup.cs文件:
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.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
// Add application services.
services.AddTransient<IEmailSender, EmailSender>();
services.AddMvc();
// Add http context
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
}
// 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.UseBrowserLink();
app.UseDeveloperExceptionPage();
app.UseDatabaseErrorPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
}
app.UseStaticFiles();
app.UseAuthentication();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
}
【问题讨论】:
-
Development environment should not be enabled in deployed applications不是错误消息。这是关于在生产环境中不启用开发模式的提示。您可能会得到一个“正常”的 HttpStatus 代码 500。请做 启用开发,让它快速显示实际的错误消息。并且不要忘记在测试后禁用它。 -
@rickvdbosch,好的,但是怎么样?我已经完成了上述所有操作的相反操作,仍然出现这个“提示”错误。
-
将
ASPNETCORE_ENVIRONMENT变量设置为Development并重新启动应用程序。如果你有一个相当标准的实现,那么 Development 很可能会给你一个 DeveloperExceptionPage -
我也已经完成了,这也没有帮助@rickvdbosch
-
你应该也可以在网络配置中设置它
标签: amazon-web-services .net-core asp.net-core-mvc amazon-elastic-beanstalk