How to do it...

We'll dive into using TagHelpers by creating a project that behaves differently in each Environment: Development, Staging, and Production:

  1. First, let's use the Environment TagHelper:
<environment names="Development"> 
<link rel="stylesheet"  
href="~/lib/bootstrap/dist/css/bootstrap.css" /> 
</environment> 
<environment names="Staging,Production"> 
<link rel="stylesheet" href=https://ajax.aspnetcdn.com/ajax/ bootstrap/3.3.6/css/bootstrap.min.css /> 
</environment> 

The Environment TagHelper is mapped with an environment variable defined in the application's properties, ASPNETCORE_ENVIRONMENT. This variable is used in the application configuration in Startup.cs as an IHostingEnvironment type. The Environment TagHelper often includes ...

Get ASP.NET Core MVC 2.0 Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.