You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: aspnetcore/blazor/hosting-model-configuration.md
+59-3Lines changed: 59 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@ description: Learn about Blazor hosting model configuration, including how to in
5
5
monikerRange: '>= aspnetcore-3.1'
6
6
ms.author: riande
7
7
ms.custom: mvc
8
-
ms.date: 03/24/2020
8
+
ms.date: 04/02/2020
9
9
no-loc: [Blazor, SignalR]
10
10
uid: blazor/hosting-model-configuration
11
11
---
@@ -19,14 +19,70 @@ This article covers hosting model configuration.
19
19
20
20
## Blazor WebAssembly
21
21
22
+
### Environment
23
+
24
+
When running an app locally, the environment defaults to Development. When the app is published, the environment defaults to Production.
25
+
26
+
A hosted Blazor WebAssembly app picks up the environment from the server via a middleware that communicates the environment to the browser by adding the `blazor-environment` header. The value of the header is the environment. The hosted Blazor app and the server app share the same environment. For more information, including how to configure the environment, see <xref:fundamentals/environments>.
27
+
28
+
For a standalone app running locally, the development server adds the `blazor-environment` header to specify the Development environment. To specify the environment for other hosting environments, add the `blazor-environment` header.
29
+
30
+
In the following example for IIS, add the custom header to the published *web.config* file. The *web.config* file is located in the *bin/Release/{TARGET FRAMEWORK}/publish* folder:
31
+
32
+
```xml
33
+
<?xml version="1.0" encoding="UTF-8"?>
34
+
<configuration>
35
+
<system.webServer>
36
+
37
+
...
38
+
39
+
<httpProtocol>
40
+
<customHeaders>
41
+
<addname="blazor-environment"value="Staging" />
42
+
</customHeaders>
43
+
</httpProtocol>
44
+
</system.webServer>
45
+
</configuration>
46
+
```
47
+
48
+
Obtain the app's environment in a component by injecting `IWebAssemblyHostEnvironment` and reading the `Environment` property:
As of the ASP.NET Core 3.2 Preview 3 release, Blazor WebAssembly supports configuration from:
23
63
24
64
**wwwroot/appsettings.json*
25
65
**wwwroot/appsettings.{ENVIRONMENT}.json*
26
66
27
-
In a Blazor Hosted app, the [runtime environment](xref:fundamentals/environments) is the same as the server app's value.
67
+
Add an *appsettings.json* file in the *wwwroot* folder:
28
68
29
-
When running the app locally, the environment defaults to Development. When the app is published, the environment defaults to Production. For more information, including how to configure the environment, see <xref:fundamentals/environments>.
69
+
```json
70
+
{
71
+
"message": "Hello from config!"
72
+
}
73
+
```
74
+
75
+
Inject an <xref:Microsoft.Extensions.Configuration.IConfiguration> instance into a component to access the configuration data:
76
+
77
+
```razor
78
+
@page "/"
79
+
@using Microsoft.Extensions.Configuration
80
+
@inject IConfiguration Configuration
81
+
82
+
<h1>Configuration example</h1>
83
+
84
+
<p>@Configuration["message"]</p>
85
+
```
30
86
31
87
> [!WARNING]
32
88
> Configuration in a Blazor WebAssembly app is visible to users. **Don't store app secrets or credentials in configuration.**
0 commit comments