visual-studioiisasp.net-corevisual-studio-publish

IIS error because ASPNETCORE_ENVIRONMENT set to development but its not


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.


Solution

  • 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.