1
votes

ASP.Net Core 2.2 web app being published to a dev/test server. In my publish profile, I have this

  <PropertyGroup>
    <EnvironmentName>Test</EnvironmentName>
  </PropertyGroup>

When I publish to the destination, I look at the web.config file, I see the correct environment setting.

name="ASPNETCORE_ENVIRONMENT" value="Test" 

However, when I hit the website in a browser, I get the error suggesting that the environment var is set to Development ?

Error. An error occurred while processing your request.

Request ID: 0HLLKB82R933P:00000002 Development Mode

Swapping to the Development environment displays detailed information about the error that occurred.

The Development environment shouldn't be enabled for deployed applications. It can result in displaying sensitive information from exceptions to end users. For local debugging, enable the Development environment by setting the ASPNETCORE_ENVIRONMENT environment variable to Development and restarting the app.

[ update ]
If I changed the ASPNETCORE_ENVIRONMENT value to "Test" in the project settings, before publishing, the app works as expected. As another commenter before has suggested, this might be something that only works as expected for "in-process" apps. So Im looking at that next.

1
Which hosting model are you using? In process or out of process?Chris Pratt
You're referring to the project settings, and it's been set to "default", which is the out-of-processbitshift
I'm not 100% sure, but I think the web.config environment variables may only apply when you're running in process. I can't find anything to in this regard in the docs, but, in general, most things in web.config are ignored when running out of process. If you need to remain out of process, you can try passing the environment as a command line argument instead (--environment) or just set an environment variable manually on the system.Chris Pratt
What value is set in launchSettings.json file?abhinav pratap
@abhinav - hmmm, i didnt even think of considering that. its set to "Development", but I also managed to get publish working again without modifying this file. See above for update.bitshift

1 Answers

1
votes

What you observed is perfectly normal.

Your web app threw an unhandled exception, and ASP.NET Core runtime verified the environment. As the environment "Test" is used instead of "Development", it showed this page to tell you what was wrong.

If you modify the environment to Development, there will be an error page with more information (call stack and so on) to reveal what really happens.

To get rid of such error pages (either for "Test" or "Development") you need to fix your code to handle the actual exception.