I tried to set the staging environment where I can see the detailed error. If I switch the ASPNETCORE_ENVIRONMENT
to Development
, I will see the detailed error. I am going to explain below.
launchSettings.json
:
{
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"TestApp-DEV": {
"commandName": "Project",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"dotnetRunMessages": true,
"applicationUrl": "https://localhost:7000;http://localhost:5000"
},
"TestApp-PROD": {
"commandName": "Project",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Production"
},
"dotnetRunMessages": true,
"applicationUrl": "https://localhost:7000;;
},
"TestApp-Staging": {
"commandName": "Project",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Staging"
},
"dotnetRunMessages": true,
"applicationUrl": "https://localhost:7000;;
}
},
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:40116",
"sslPort": 44301
}
}
}
appsettings.json
has 3 different configuration files. Note that the appsettings.Staging.json
and appsettings.Production.json
are almost the same configuration.
If I run the project at localhost with "TestApp-DEV" environment, I will see the detailed error page.
If I run the project at localhost as either Staging or Production, I will receive this message:
My workaround for troubleshooting related to production environment is that I rename the appsettings.Development.json
to something temporary, then change the name appsettings.Staging.json
to appsettings.Development.json
and run the project in development env so I can see the detailed error that is related to production. After that, revert back the appsettings names.
Is there a way show the detailed error when I run the project at locolhost in staging or projection environment?
I tried to set the staging environment where I can see the detailed error. If I switch the ASPNETCORE_ENVIRONMENT
to Development
, I will see the detailed error. I am going to explain below.
launchSettings.json
:
{
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"TestApp-DEV": {
"commandName": "Project",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"dotnetRunMessages": true,
"applicationUrl": "https://localhost:7000;http://localhost:5000"
},
"TestApp-PROD": {
"commandName": "Project",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Production"
},
"dotnetRunMessages": true,
"applicationUrl": "https://localhost:7000;https://TestApp.scm.azurewebsites"
},
"TestApp-Staging": {
"commandName": "Project",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Staging"
},
"dotnetRunMessages": true,
"applicationUrl": "https://localhost:7000;https://TestApp.scm.azurewebsites"
}
},
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:40116",
"sslPort": 44301
}
}
}
appsettings.json
has 3 different configuration files. Note that the appsettings.Staging.json
and appsettings.Production.json
are almost the same configuration.
If I run the project at localhost with "TestApp-DEV" environment, I will see the detailed error page.
If I run the project at localhost as either Staging or Production, I will receive this message:
My workaround for troubleshooting related to production environment is that I rename the appsettings.Development.json
to something temporary, then change the name appsettings.Staging.json
to appsettings.Development.json
and run the project in development env so I can see the detailed error that is related to production. After that, revert back the appsettings names.
Is there a way show the detailed error when I run the project at locolhost in staging or projection environment?
Share Improve this question edited Feb 4 at 21:48 Milacay asked Feb 4 at 19:36 MilacayMilacay 1,5359 gold badges36 silver badges63 bronze badges 1- What version of ASP.NET Core are you running? Ideally it would be great to have a minimal reproducible example at hand. – Guru Stron Commented Feb 4 at 19:49
1 Answer
Reset to default 3Probably the easiest approach would be to just use developer exception page on the staging:
// somewhere close to var app = builder.Build();
if (app.Environment.IsStaging())
{
app.UseDeveloperExceptionPage();
}
Probably you can add extra config value to check if it should be enabled (and set it up in launchSettings
or appSettings
).
Also you can use conditional pipeline. For example:
if (app.Environment.IsStaging())
{
app.UseWhen(ctx => ctx.Request.Host.Host.Equals("localhost", StringComparison.OrdinalIgnoreCase),
appBuilder => appBuilder.UseDeveloperExceptionPage());
}
or just wrap the UseDeveloperExceptionPage
into #if DEBUG
as @Jeremy Lakeman if this is needed only for debug builds and local debugging.