Skip to content

Commit e8dc304

Browse files
authored
Merge pull request #17726 from dotnet/master
2 parents e72a58d + 208f824 commit e8dc304

7 files changed

Lines changed: 168 additions & 11 deletions

File tree

aspnetcore/blazor/hosting-model-configuration.md

Lines changed: 62 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description: Learn about Blazor hosting model configuration, including how to in
55
monikerRange: '>= aspnetcore-3.1'
66
ms.author: riande
77
ms.custom: mvc
8-
ms.date: 03/24/2020
8+
ms.date: 04/07/2020
99
no-loc: [Blazor, SignalR]
1010
uid: blazor/hosting-model-configuration
1111
---
@@ -19,14 +19,73 @@ This article covers hosting model configuration.
1919

2020
## Blazor WebAssembly
2121

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+
<add name="blazor-environment" value="Staging" />
42+
</customHeaders>
43+
</httpProtocol>
44+
</system.webServer>
45+
</configuration>
46+
```
47+
48+
> [!NOTE]
49+
> To use a custom *web.config* file for IIS that isn't overwritten when the app is published to the *publish* folder, see <xref:host-and-deploy/blazor/webassembly#use-a-custom-webconfig>.
50+
51+
Obtain the app's environment in a component by injecting `IWebAssemblyHostEnvironment` and reading the `Environment` property:
52+
53+
```razor
54+
@page "/"
55+
@using Microsoft.AspNetCore.Components.WebAssembly.Hosting
56+
@inject IWebAssemblyHostEnvironment HostEnvironment
57+
58+
<h1>Environment example</h1>
59+
60+
<p>Environment: @HostEnvironment.Environment</p>
61+
```
62+
63+
### Configuration
64+
2265
As of the ASP.NET Core 3.2 Preview 3 release, Blazor WebAssembly supports configuration from:
2366

2467
* *wwwroot/appsettings.json*
2568
* *wwwroot/appsettings.{ENVIRONMENT}.json*
2669

27-
In a Blazor Hosted app, the [runtime environment](xref:fundamentals/environments) is the same as the server app's value.
70+
Add an *appsettings.json* file in the *wwwroot* folder:
71+
72+
```json
73+
{
74+
"message": "Hello from config!"
75+
}
76+
```
77+
78+
Inject an <xref:Microsoft.Extensions.Configuration.IConfiguration> instance into a component to access the configuration data:
2879

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>.
80+
```razor
81+
@page "/"
82+
@using Microsoft.Extensions.Configuration
83+
@inject IConfiguration Configuration
84+
85+
<h1>Configuration example</h1>
86+
87+
<p>Message: @Configuration["message"]</p>
88+
```
3089

3190
> [!WARNING]
3291
> Configuration in a Blazor WebAssembly app is visible to users. **Don't store app secrets or credentials in configuration.**

aspnetcore/blazor/integrate-components.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description: Learn about data binding scenarios for components and DOM elements
55
monikerRange: '>= aspnetcore-3.1'
66
ms.author: riande
77
ms.custom: mvc
8-
ms.date: 03/17/2020
8+
ms.date: 04/01/2020
99
no-loc: [Blazor, SignalR]
1010
uid: blazor/integrate-components
1111
---
@@ -105,6 +105,19 @@ To support routable Razor components in Razor Pages apps:
105105

106106
Components use the shared *_Layout.cshtml* file for their layout.
107107

108+
<xref:Microsoft.AspNetCore.Mvc.Rendering.RenderMode> configures whether the `App` component:
109+
110+
* Is prerendered into the page.
111+
* Is rendered as static HTML on the page or if it includes the necessary information to bootstrap a Blazor app from the user agent.
112+
113+
| Render Mode | Description |
114+
| ----------- | ----------- |
115+
| <xref:Microsoft.AspNetCore.Mvc.Rendering.RenderMode.ServerPrerendered> | Renders the `App` component into static HTML and includes a marker for a Blazor Server app. When the user-agent starts, this marker is used to bootstrap a Blazor app. |
116+
| <xref:Microsoft.AspNetCore.Mvc.Rendering.RenderMode.Server> | Renders a marker for a Blazor Server app. Output from the `App` component isn't included. When the user-agent starts, this marker is used to bootstrap a Blazor app. |
117+
| <xref:Microsoft.AspNetCore.Mvc.Rendering.RenderMode.Static> | Renders the `App` component into static HTML. |
118+
119+
For more information on the Component Tag Helper, see <xref:mvc/views/tag-helpers/builtin-th/component-tag-helper>.
120+
108121
1. Add a low-priority route for the *_Host.cshtml* page to endpoint configuration in `Startup.Configure`:
109122

110123
```csharp
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
## Custom user flows
2+
3+
The Microsoft Authentication Library (`Microsoft.Authentication.WebAssembly.Msal`) doesn't support [AAD B2C user flows](/azure/active-directory-b2c/user-flow-overview) by default. Create custom user flows in developer code.
4+
5+
For more information on how to build a challenge for a custom user flow, see [User flows in Azure Active Directory B2C](/azure/active-directory-b2c/user-flow-overview).

aspnetcore/mvc/controllers/routing.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,11 @@ Replaces:
8787
endpoints.MapControllerRoute("default", "{controller=Home}/{action=Index}/{id?}");
8888
```
8989

90-
Routing is configured using the <xref:Microsoft.AspNetCore.Builder.EndpointRoutingApplicationBuilderExtensions.UseRouting*> and <xref:Microsoft.AspNetCore.Builder.EndpointRoutingApplicationBuilderExtensions.UseEndpoints*> middleware. To use controllers:
91-
92-
* Call <xref:Microsoft.AspNetCore.Builder.ControllerEndpointRouteBuilderExtensions.MapControllers*> inside `UseEndpoints` to map [attribute routed](#ar) controllers.
93-
* Call <xref:Microsoft.AspNetCore.Builder.ControllerEndpointRouteBuilderExtensions.MapControllerRoute*> or <xref:Microsoft.AspNetCore.Builder.ControllerEndpointRouteBuilderExtensions.MapAreaControllerRoute*>, to map [conventionally routed](#cr) controllers.
90+
> [!IMPORTANT]
91+
> Routing is configured using the <xref:Microsoft.AspNetCore.Builder.EndpointRoutingApplicationBuilderExtensions.UseRouting*> and <xref:Microsoft.AspNetCore.Builder.EndpointRoutingApplicationBuilderExtensions.UseEndpoints*> middleware. To use controllers:
92+
>
93+
> * Call <xref:Microsoft.AspNetCore.Builder.ControllerEndpointRouteBuilderExtensions.MapControllers*> inside `UseEndpoints` to map [attribute routed](#ar) controllers.
94+
> * Call <xref:Microsoft.AspNetCore.Builder.ControllerEndpointRouteBuilderExtensions.MapControllerRoute*> or <xref:Microsoft.AspNetCore.Builder.ControllerEndpointRouteBuilderExtensions.MapAreaControllerRoute*>, to map [conventionally routed](#cr) controllers.
9495
9596
<a name="routing-conventional-ref-label"></a>
9697
<a name="crd"></a>

aspnetcore/mvc/views/tag-helpers/built-in/component-tag-helper.md

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ author: guardrex
44
ms.author: riande
55
description: Learn how to use the ASP.NET Core Component Tag Helper to render Razor components in pages and views.
66
ms.custom: mvc
7-
ms.date: 03/18/2020
7+
ms.date: 04/01/2020
88
no-loc: [Blazor, SignalR]
99
uid: mvc/views/tag-helpers/builtin-th/component-tag-helper
1010
---
@@ -14,12 +14,25 @@ By [Daniel Roth](https://github.com/danroth27) and [Luke Latham](https://github.
1414

1515
To render a component from a page or view, use the [Component Tag Helper](xref:Microsoft.AspNetCore.Mvc.TagHelpers.ComponentTagHelper).
1616

17+
## Prerequisites
18+
19+
Follow the guidance in the *Prepare the app to use components in pages and views* section of the <xref:blazor/integrate-components#prepare-the-app-to-use-components-in-pages-and-views> article.
20+
21+
## Component Tag Helper
22+
1723
The following Component Tag Helper renders the `Counter` component in a page or view:
1824

1925
```cshtml
26+
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
27+
@using {APP ASSEMBLY}.Pages
28+
29+
...
30+
2031
<component type="typeof(Counter)" render-mode="ServerPrerendered" />
2132
```
2233

34+
The preceding example assumes that the `Counter` component is in the app's *Pages* folder.
35+
2336
The Component Tag Helper can also pass parameters to components. Consider the following `ColorfulCheckbox` component that sets the check box label's color and size:
2437

2538
```razor
@@ -51,10 +64,17 @@ The Component Tag Helper can also pass parameters to components. Consider the fo
5164
The `Size` (`int`) and `Color` (`string`) [component parameters](xref:blazor/components#component-parameters) can be set by the Component Tag Helper:
5265

5366
```cshtml
67+
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
68+
@using {APP ASSEMBLY}.Shared
69+
70+
...
71+
5472
<component type="typeof(ColorfulCheckbox)" render-mode="ServerPrerendered"
5573
param-Size="14" param-Color="@("blue")" />
5674
```
5775

76+
The preceding example assumes that the `ColorfulCheckbox` component is in the app's *Shared* folder.
77+
5878
The following HTML is rendered in the page or view:
5979

6080
```html
@@ -68,6 +88,60 @@ Passing a quoted string requires an [explicit Razor expression](xref:mvc/views/r
6888

6989
The parameter type must be JSON serializable, which typically means that the type must have a default constructor and settable properties. For example, you can specify a value for `Size` and `Color` in the preceding example because the types of `Size` and `Color` are primitive types (`int` and `string`), which are supported by the JSON serializer.
7090

91+
In the following example, a class object is passed to the component:
92+
93+
*MyClass.cs*:
94+
95+
```csharp
96+
public class MyClass
97+
{
98+
public MyClass()
99+
{
100+
}
101+
102+
public int MyInt { get; set; } = 999;
103+
public string MyString { get; set; } = "Initial value";
104+
}
105+
```
106+
107+
**The class must have a public parameterless constructor.**
108+
109+
*Shared/MyComponent.razor*:
110+
111+
```razor
112+
<h2>MyComponent</h2>
113+
114+
<p>Int: @MyObject.MyInt</p>
115+
<p>String: @MyObject.MyString</p>
116+
117+
@code
118+
{
119+
[Parameter]
120+
public MyClass MyObject { get; set; }
121+
}
122+
```
123+
124+
*Pages/MyPage.cshtml*:
125+
126+
```cshtml
127+
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
128+
@using {APP ASSEMBLY}
129+
@using {APP ASSEMBLY}.Shared
130+
131+
...
132+
133+
@{
134+
var myObject = new MyClass();
135+
myObject.MyInt = 7;
136+
myObject.MyString = "Set by MyPage";
137+
}
138+
139+
<component type="typeof(MyComponent)" render-mode="ServerPrerendered"
140+
param-MyObject="@myObject" />
141+
```
142+
143+
The preceding example assumes that the `MyComponent` component is in the app's *Shared* folder. `MyClass` is in the app's namespace (`{APP ASSEMBLY}`).
144+
71145
<xref:Microsoft.AspNetCore.Mvc.Rendering.RenderMode> configures whether the component:
72146

73147
* Is prerendered into the page.

aspnetcore/security/blazor/webassembly/hosted-with-azure-active-directory-b2c.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description:
55
monikerRange: '>= aspnetcore-3.1'
66
ms.author: riande
77
ms.custom: mvc
8-
ms.date: 04/08/2020
8+
ms.date: 04/09/2020
99
no-loc: [Blazor, SignalR]
1010
uid: security/blazor/webassembly/hosted-with-azure-active-directory-b2c
1111
---
@@ -297,6 +297,9 @@ Run the app from the Server project. When using Visual Studio, select the Server
297297
<!-- HOLD
298298
[!INCLUDE[](~/includes/blazor-security/usermanager-signinmanager.md)]
299299
-->
300+
301+
[!INCLUDE[](~/includes/blazor-security/wasm-aad-b2c-userflows.md)]
302+
300303
[!INCLUDE[](~/includes/blazor-security/troubleshoot.md)]
301304
302305
## Additional resources

aspnetcore/security/blazor/webassembly/standalone-with-azure-active-directory-b2c.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description:
55
monikerRange: '>= aspnetcore-3.1'
66
ms.author: riande
77
ms.custom: mvc
8-
ms.date: 04/08/2020
8+
ms.date: 04/09/2020
99
no-loc: [Blazor, SignalR]
1010
uid: security/blazor/webassembly/standalone-with-azure-active-directory-b2c
1111
---
@@ -133,6 +133,8 @@ For more information, see <xref:security/blazor/webassembly/additional-scenarios
133133
134134
[!INCLUDE[](~/includes/blazor-security/authentication-component.md)]
135135
136+
[!INCLUDE[](~/includes/blazor-security/wasm-aad-b2c-userflows.md)]
137+
136138
[!INCLUDE[](~/includes/blazor-security/troubleshoot.md)]
137139
138140
## Additional resources

0 commit comments

Comments
 (0)