0
votes

When I publish my .NET core app to a development IIS server, I make a call to the API and the method works fine locally. This method makes a Db call using a connection string stored in
appSettings.json as well as appSettings.Development.json

Observations:
- Yes, I have ASPNETCORE_ENVIRONMENT = Development and I have both an appSettings.json file AND appSettings.Development.json file - So I started looking at the published files and I had BOTH of these json files in the published folder, even though appSettings.Development.json properties is set to "Build Action" = content and Copy to Output Directory = Do Not Copy - If I comment out the code that his the Db, and return dummy data, and republish the api, i get the results fine with no complaints about "development mode"



Error I get when calling the API trying to hit the Db

Error. An error occurred while processing your request.

Request ID: 0HLL1GOCEHH73:00000001

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.

Questions:
- The Db connection strings are in both

[ update ]

Brain-fart! The db connection strings were using 'trusted', so no wonder they worked locally! Once I put in the credentials, and re-published, things worked like I expected. However, the error message threw me off.

Im still not sure why I have both of those appSettings files published? Which one will it use?

1
the db call works locally?Neil
See update abovebitshift

1 Answers

-1
votes

I am assuming your appsetting files are named as following:

  1. appSettings.json
  2. appSettings.dev.json

typically, you have to explicitly set the environment to dev. if you use Visual Studio for development, it sets an environment variable that tells the application to put it in dev mode.

Without seeing the initializing logic, I would say in prod it will use the appSettings.json.

Take a look at this article, it explains configuration in more details.