ASP.NET Core Interview Question #19
What are environments in ASP.NET Core?
ASP.NET Core Fundamentals Junior Beginner
Quick Interview Answer
Environments allow an ASP.NET Core application to change behavior and configuration according to where it is running. Common environment names are Development, Staging, and Production.
Detailed Explanation
Environments allow an ASP.NET Core application to change behavior and configuration according to where it is running. Common environment names are Development, Staging, and Production.
The current environment is available through IWebHostEnvironment or WebApplication.Environment. It is often used to select exception handling, diagnostics, configuration files, and other environment-specific behavior.
Production behavior should not expose developer exception details or sensitive diagnostic information to end users.
Code Example
if (app.Environment.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
app.UseHsts();
}