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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.