ASP.NET Core Tutorial – Session 6 – Environment variable & Hosting Environment

ASP.NET Core Session6 Feature Image

We allocate this session of ASP.NET Core tutorial to introduce Environment variable and Hosting Envirionment. During this session, we explain about the location and the way of creating Environment Variable. Also, we talk about popular Hosting Environment and go through details of its conditions.

Environment Variable

Environment Variable could be created or edited in launchSettings.json file(we have introduced tis file in session five), operation system or web server. Below you can see the source code of launchSettings.json. The related section has been highlighted. This variable implies the stage of Hosting Environment, and as you can see below, it is possible to create an Environment Variable for each launcher profile.

We can also create an Environment Variable in operation system. Bear in mind, if the web server or launchSettings.json file would not be determined at the time of application deployment, the default amount of application safety on operation system or web server would be production. On Windows operation system, we can set this variable from this path: System Properties->Environment Variable. It is completely explained in our video.

Environment Variables in Windows for setting Environment Variables
System Properties In Windows for setting Environment Variables

Moreover we can create and set Environment Variable on web server. For example in IIS, we have this option in Configuration Editor section of application in system.webServer/aspNetCore. You can see it below and we explain about it in our video.

system.webServer/aspNetCore in IIS for setting Environment Variables
Configuration Editor In IIS  for setting Environment Variables

Value of this Environment Variable can be accessible through Startup Class and Configure method. This method has two parameters that one of them is IWebHostEnvironment and its name is env. Via this parameter we can have access to Environment Variables. Below code explains this matter.

Hosting Environment

Generally, development teams and company separate each development process to three different stages. Development, Staging and Production.

Development Hosting Environment

This stage is for daily application or website development, development team implement their codes and do troubleshooting and debugging during this stage. In development stage we upload none minified CSS and JavaScript files. Also in case of exception, application shows Developer Exception Page that contains technical information which help developer to debug the code.

Staging Hosting Environment

Application or website should be as much as possible same as final production. During this stage we check ant possible deployment issue. Also, we still upload none minified CSS and JavaScript file, but application in case of exception will show user friendly exception page that contains generic message and encourage users to report the problem to site admin or development team. Moreover, during this stage developer team does not do code troubleshooting and debugging.

Production Hosting Environment

This stage is for presenting final production to be used for daily business. We upload minified CSS and JavaScript file in this stage for more security and performance. Moreover, in case of exception, application shows a user friendly page and we should not show developer exception page in this stage. Because, first of all those information are not understandable for users and malicious user can use those information to hack our application.

If you need more details, watch this session video. Also, for being updated about our coming sessions, follow us on Instagram, Facebook, Telegram or YouTube and be in touch with us here.

You can download this Session Slides form HERE

0.00 avg. rating (0% score) - 0 votes


0 0 votes
Article Rating

Inline Feedbacks
View all comments