Does a change on appsettings.json require IIS restart?

Cenk 1,036 Reputation points
2023-06-14T10:38:26.1633333+00:00

Hi,

I want to read some settings from appsettings.json. There might be additions to those settings and I wonder if I change/add a new setting to the JSON file, should I need to restart IIS? How can I get away without restarting, is there any options to reload the new values? By the way, I am working on ASP.NET Core 6 web API project.

Thank you.

Developer technologies | ASP.NET | ASP.NET Core
{count} votes

2 answers

Sort by: Most helpful
  1. Rubens Guimarães 175 Reputation points Microsoft Regional Director
    2023-06-14T11:06:08.09+00:00

    Yes! You need to reestart the webapp. But if you want to minimize impacts to end users, you can adopt a zero downtime architecture using slots or a vertical load balancer. As one endpoint is updated, it is decommissioned on the balancer, redirecting traffic to the second endpoint.

    Some options to configure settings:

    For ASP.NET and ASP.NET Core developers, setting app settings in App Service are like setting them in <appSettings> in Web.config or appsettings.json, but the values in App Service override the ones in Web.config or appsettings.json. You can keep development settings (for example, local MySQL password) in Web.config or appsettings.json and production secrets (for example, Azure MySQL database password) safely in App Service. The same code uses your development settings when you debug locally, and it uses your production secrets when deployed to Azure.

    1 person found this answer helpful.
    0 comments No comments

  2. Bruce (SqlWork.com) 77,926 Reputation points Volunteer Moderator
    2023-06-14T15:41:44.1633333+00:00

    you can use IOptionsSnapshot to re-load the app setting values when the file changes. But you need to be sure all use of the settings values uses the snapshot and never store the value. be careful with registering services.

    for instance if you inject a database context, you would need to use a factory, so that it was always used the latest appsettings connection string.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.