Skip to content

Commit f2d1b87

Browse files
Update Environments (#17740)
* Update Environments * Update Environments * Update Environments * work * work * work * work * work * work * work * work * work * work * work * work * work * work * work * work * Apply suggestions from code review Co-Authored-By: Kirk Larkin <6025110+serpent5@users.noreply.github.com> * react to feedback * react to feedback * Apply suggestions from code review Co-Authored-By: Kirk Larkin <6025110+serpent5@users.noreply.github.com> Co-authored-by: Kirk Larkin <6025110+serpent5@users.noreply.github.com>
1 parent 1fad48a commit f2d1b87

48 files changed

Lines changed: 40257 additions & 249 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

aspnetcore/fundamentals/environments.md

Lines changed: 105 additions & 249 deletions
Large diffs are not rendered by default.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Use IntelliSense to learn about possible attributes.
2+
// Hover to view descriptions of existing attributes.
3+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
4+
{
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": ".NET Core Launch (web)",
9+
"type": "coreclr",
10+
// Configuration ommitted for brevity.
11+
"request": "launch",
12+
"preLaunchTask": "build",
13+
"program": "${workspaceFolder}/bin/Debug/netcoreapp3.1/EnvironmentsSample.dll",
14+
"args": [],
15+
"cwd": "${workspaceFolder}",
16+
"stopAtEntry": false,
17+
"internalConsoleOptions": "openOnSessionStart",
18+
"launchBrowser": {
19+
"enabled": true,
20+
"args": "${auto-detect-url}",
21+
"windows": {
22+
"command": "cmd.exe",
23+
"args": "/C start ${auto-detect-url}"
24+
},
25+
"osx": {
26+
"command": "open"
27+
},
28+
"linux": {
29+
"command": "xdg-open"
30+
}
31+
},
32+
"env": {
33+
"ASPNETCORE_ENVIRONMENT": "Development",
34+
"ASPNETCORE_URLS": "https://localhost:5001",
35+
"ASPNETCORE_DETAILEDERRORS": "1",
36+
"ASPNETCORE_SHUTDOWNTIMEOUTSECONDS": "3"
37+
},
38+
// Configuration ommitted for brevity.
39+
"sourceFileMap": {
40+
"/Views": "${workspaceFolder}/Views"
41+
}
42+
},
43+
{
44+
"name": ".NET Core Attach",
45+
"type": "coreclr",
46+
"request": "attach",
47+
"processId": "${command:pickProcess}"
48+
}
49+
]
50+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
// See https://go.microsoft.com/fwlink/?LinkId=733558
3+
// for the documentation about the tasks.json format
4+
"version": "2.0.0",
5+
"tasks": [
6+
{
7+
"label": "build",
8+
"type": "shell",
9+
"command": "dotnet",
10+
"args": [
11+
"build",
12+
"${workspaceFolder}/EnvironmentsSample.csproj"
13+
],
14+
"group": "build",
15+
"presentation": {
16+
// Reveal the output only if unrecognized errors occur.
17+
"reveal": "silent"
18+
},
19+
// Use the standard MS compiler pattern to detect errors, warnings and infos
20+
"problemMatcher": "$msCompile"
21+
}
22+
]
23+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netcoreapp3.1</TargetFramework>
5+
<Configurations>Debug;Release;IISxMultiConfig</Configurations>
6+
</PropertyGroup>
7+
8+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='IISxMultiConfig|AnyCPU'">
9+
<DefineConstants>TRACE;MULTI</DefineConstants>
10+
</PropertyGroup>
11+
12+
13+
14+
</Project>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
@page
2+
@inject Microsoft.AspNetCore.Hosting.IWebHostEnvironment hostingEnv
3+
@model AboutModel
4+
@{
5+
ViewData["Title"] = "About";
6+
}
7+
<h2>@ViewData["Title"]</h2>
8+
<h3>@Model.Message</h3>
9+
10+
<p> ASPNETCORE_ENVIRONMENT = @hostingEnv.EnvironmentName</p>
11+
12+
<environment include="Development">
13+
<div>The effective tag is: &lt;environment include="Development"&gt;</div>
14+
</environment>
15+
<environment exclude="Development">
16+
<div>The effective tag is: &lt;environment exclude="Development"&gt;</div>
17+
</environment>
18+
<environment include="Staging,Development,Staging_2">
19+
<div>
20+
The effective tag is:
21+
&lt;environment include="Staging,Development,Staging_2"&gt;
22+
</div>
23+
</environment>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using Microsoft.AspNetCore.Mvc.RazorPages;
2+
using System;
3+
4+
namespace EnvironmentsSample.Pages
5+
{
6+
public class AboutModel : PageModel
7+
{
8+
public string Message { get; set; }
9+
10+
public void OnGet()
11+
{
12+
var env = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
13+
Message = $"ASPNETCORE_ENVIRONMENT = {env}";
14+
}
15+
}
16+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
@page
2+
@model ErrorModel
3+
@{
4+
ViewData["Title"] = "Error";
5+
}
6+
7+
<h1 class="text-danger">Error.</h1>
8+
<h2 class="text-danger">An error occurred while processing your request.</h2>
9+
10+
@if (Model.ShowRequestId)
11+
{
12+
<p>
13+
<strong>Request ID:</strong> <code>@Model.RequestId</code>
14+
</p>
15+
}
16+
17+
<h3>Development Mode</h3>
18+
<p>
19+
Swapping to the <strong>Development</strong> environment displays detailed information about the error that occurred.
20+
</p>
21+
<p>
22+
<strong>The Development environment shouldn't be enabled for deployed applications.</strong>
23+
It can result in displaying sensitive information from exceptions to end users.
24+
For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>
25+
and restarting the app.
26+
</p>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Diagnostics;
4+
using System.Linq;
5+
using System.Threading.Tasks;
6+
using Microsoft.AspNetCore.Mvc;
7+
using Microsoft.AspNetCore.Mvc.RazorPages;
8+
using Microsoft.Extensions.Logging;
9+
10+
namespace EnvironmentsSample.Pages
11+
{
12+
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
13+
public class ErrorModel : PageModel
14+
{
15+
public string RequestId { get; set; }
16+
17+
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
18+
19+
private readonly ILogger<ErrorModel> _logger;
20+
21+
public ErrorModel(ILogger<ErrorModel> logger)
22+
{
23+
_logger = logger;
24+
}
25+
26+
public void OnGet()
27+
{
28+
RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
29+
}
30+
}
31+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
@page
2+
@model IndexModel
3+
@{
4+
ViewData["Title"] = "Home page";
5+
}
6+
7+
<div class="text-center">
8+
<h1 class="display-4">Welcome</h1>
9+
<p>Learn about <a href="https://docs.microsoft.com/aspnet/core">building Web apps with ASP.NET Core</a>.</p>
10+
</div>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using Microsoft.AspNetCore.Mvc;
6+
using Microsoft.AspNetCore.Mvc.RazorPages;
7+
using Microsoft.Extensions.Logging;
8+
9+
namespace EnvironmentsSample.Pages
10+
{
11+
public class IndexModel : PageModel
12+
{
13+
private readonly ILogger<IndexModel> _logger;
14+
15+
public IndexModel(ILogger<IndexModel> logger)
16+
{
17+
_logger = logger;
18+
}
19+
20+
public void OnGet()
21+
{
22+
23+
}
24+
}
25+
}

0 commit comments

Comments
 (0)