Significance of Launchsetting.json file

Launch Setting File Importance in Asp.Net Core By Sagar Jaybhay

{
  "iisSettings": {
    "windowsAuthentication": false, 
    "anonymousAuthentication": true, 
    "iisExpress": {
      "applicationUrl": "http://localhost:62605",
      "sslPort": 44385
    }
  },
  "profiles": {
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "LearnAspCore": {
      "commandName": "Project",
      "launchBrowser": true,
      "applicationUrl": "https://localhost:5001;http://localhost:5000",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    }
  }
}

This is default code is created when you create the project. In this file there are 2 default profiles are present IIS Express and by your project name. In this when you run the project by using Ctrl+F5 then IIS  Express profile is used.

As per name suggest these file profiles are used to launch the application.

What is appsettings.json file in asp.net core?

In asp .net core configuration settings are come from different sources and in that one of the source us appsettings.json file.

Different types of Configuration Sources in asp.net core?

  • Files( appsettings.json)
  • User secrets
  • Environment variables
  • Command-line arguments

Usually, the information is stored in the file is as key-value pair and how to read appsetting.json file are like below?

In this, you need to add IConfiguration or need to inject this into the constructor of this startup class and then by using this object you can get the value of this.

AppSetting File

{
  "Logging": {
    "LogLevel": {
      "Default": "Warning"
    }
  },
  "AllowedHosts": "*",
  "SomeIncreptedKey": "*&*^%)hjaasdlaj*&("
}

Below is StartUp class file :-

public Startup(IConfiguration configuration)
        {
            _config = configuration;
        }
_config["SomeIncreptedKey"]

But if you use the same key in development file means appsetting.development.json then this value is overridden with development file value and you can use this. It means if we have an environment setting file this will overwrite the default file setting. If you want to store environment variables you can use launchsetting.json file.

If you pass the value from the command line using the same key which is used previously then this will override all previous values with new command line value. To run the project from the command line.

Dotnet run SomeIncreptedKey=”adkahfsfhuihf”
Dotnet 

Sagar Jaybhay, from Maharashtra, India, is currently a Senior Software Developer. He has continuously grown in the roles that he has held in the more than seven years he has been with this company. Sagar Jaybhay is an excellent team member and prides himself on his work contributions to his team and company as a whole.

Related posts