ttmind

Main Navigation

ttmind
  • jim-jams
  • Tech
  • Positive
Login

Login

Facebook Google

OR

Remember me Forgot password?

Don't have account? Signup here.

Sort by Categorys

.Net

PHP

Java

JavaScript

Database

Server

Client Side

Tools

Artificial Intelligence

Cloud

Hybrid Development

Event

Smart City

Education

Security

Scrum

Digital Marketing

APP Development

Business

Internet

Simulation

Art

Network

Microservices

Architecture

Technology

Leadership

    Top Articles

  • How Does Social Media Bring People Together?
    TTMind Author
  • How to read appSettings JSON from Class Library in ASP.NET Core
    Anil Shrestha
  • Printing Support In Asp.Net Core
    TTMind Author
  • HOW TO EXTRACT TEXT FROM IMAGE USING JAVASCRIPT (OCR with Tesseract.js)?
    Prakash Pokhrel
  • Images Upload REST API using ASP.NET Core
    Prakash Pokhrel
  • Related Topic

  • How to read appSettings JSON from Class Library in ASP.NET Core
  • Printing Support In Asp.Net Core
  • Images Upload REST API using ASP.NET Core
  • How to use IActionFilter, IAsyncActionFilter in ASP.NET Core MVC?
  • ASP.NET CORE - Blazor CRUD operation using ADO.NET
  • Tech
  • About Us
  • Contact Us
  • TechHelp
  • PositiveHelp
  • Jim-Jams Help
  • Terms & Conditions

© Copyright ttmind.com

Main Content

Environment Variables in ASP.NET Core

.Net .Net Core about 8 years ago || 3/11/2018 || 1.6 K View

  • Hide

Once you deploy your project to the production for example Azure App Service we need take care of Environment Variables and we are gonna see here how to that.

IHostingEnvironment

In your ASP.NET Core Startup class, the constructor has a IHostingEnvironment parameter. And EnvironmentName is its one of the properties. There even exits few Extension methods such as IsDevelopment(), IsStaging(), IsProduction() etc aling with the EnvironmentName..

In the sample below, you can see if the environment is development, then I’m adding the User Secrets to the ConfigurationBuilder.

In the above snapshot, What env.EnvironmentName does is that it checks whether IHostingEnvironment. Environment is equals to Development or not.

If you are outside of Visual Studio, you can manage it by editing the launchSettings.json.This is what a sample looks like.

Environment Variables

You can also add additional environment variables that will be loaded when ConfigurationBuilder.AddEnvironmentVariables() is called in Startup.

In my above example, only under development are user secrets loaded.  This is done after environemnt variables are loaded.  This means that the user secrets override any environment variables I’ve set.

Azure AppService

Once you are ready to deploy to azure, you may want to set your environment as well as other environment variables that you need which will be used instead of user secrets.  You can do this in your App Service under Application Settings.

 

  • 3
  • 0
  • 0
    • Facebook
    • Twitter
    • Google +
    • LinkedIn

About author

TTMind Author

TTMind Author

CEO, Consultant, Other

ASP.NET

Reset Your Password
Enter your email address that you used to register. We'll send you an email with your username and a link to reset your password.

Quick Survey