Skip to content

Commit 7ad5efc

Browse files
authored
Merge pull request #34335 from dotnet/main
2 parents a8bd4e2 + cfe8778 commit 7ad5efc

File tree

3 files changed

+100
-84
lines changed

3 files changed

+100
-84
lines changed

aspnetcore/blazor/globalization-localization.md

Lines changed: 92 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,9 +1075,23 @@ The component adopts the following approaches to work for either SSR or CSR comp
10751075
}
10761076
```
10771077

1078+
In the `.Client` project's `_Imports` file (`_Imports.razor`), add the namespace for the components in the `Pages` folder, updating the namespace to match your `.Client` project's namespace:
1079+
1080+
```razor
1081+
@using BlazorSample.Client.Pages
1082+
```
1083+
10781084
> [!NOTE]
10791085
> For more information on <xref:Microsoft.JSInterop.IJSInProcessRuntime>, see <xref:blazor/js-interop/call-javascript-from-dotnet#invoke-javascript-functions-without-reading-a-returned-value-invokevoidasync>.
10801086
1087+
In the `.Client` project, add the `CultureSelector` component to the `MainLayout` component. Place the following markup inside the closing `</main>` tag in the `Layout/MainLayout.razor` file:
1088+
1089+
```razor
1090+
<article class="bottom-row px-4">
1091+
<CultureSelector @rendermode="InteractiveAuto" />
1092+
</article>
1093+
```
1094+
10811095
In the `.Client` project, place the following `CultureClient` component to study how globalization works for CSR components.
10821096

10831097
`Pages/CultureClient.razor`:
@@ -1133,6 +1147,83 @@ In the `.Client` project, place the following `CultureClient` component to study
11331147
}
11341148
```
11351149

1150+
In the `.Client` project, place the following `CultureServer` component to study how globalization works for SSR components.
1151+
1152+
`Pages/CultureServer.razor`:
1153+
1154+
```razor
1155+
@page "/culture-server"
1156+
@rendermode InteractiveServer
1157+
@using System.Globalization
1158+
1159+
<PageTitle>Culture Server</PageTitle>
1160+
1161+
<h1>Culture Server</h1>
1162+
1163+
<ul>
1164+
<li><b>CurrentCulture</b>: @CultureInfo.CurrentCulture</li>
1165+
<li><b>CurrentUICulture</b>: @CultureInfo.CurrentUICulture</li>
1166+
</ul>
1167+
1168+
<h2>Rendered values</h2>
1169+
1170+
<ul>
1171+
<li><b>Date</b>: @dt</li>
1172+
<li><b>Number</b>: @number.ToString("N2")</li>
1173+
</ul>
1174+
1175+
<h2><code>&lt;input&gt;</code> elements that don't set a <code>type</code></h2>
1176+
1177+
<p>
1178+
The following <code>&lt;input&gt;</code> elements use
1179+
<code>CultureInfo.CurrentCulture</code>.
1180+
</p>
1181+
1182+
<ul>
1183+
<li><label><b>Date:</b> <input @bind="dt" /></label></li>
1184+
<li><label><b>Number:</b> <input @bind="number" /></label></li>
1185+
</ul>
1186+
1187+
<h2><code>&lt;input&gt;</code> elements that set a <code>type</code></h2>
1188+
1189+
<p>
1190+
The following <code>&lt;input&gt;</code> elements use
1191+
<code>CultureInfo.InvariantCulture</code>.
1192+
</p>
1193+
1194+
<ul>
1195+
<li><label><b>Date:</b> <input type="date" @bind="dt" /></label></li>
1196+
<li><label><b>Number:</b> <input type="number" @bind="number" /></label></li>
1197+
</ul>
1198+
1199+
@code {
1200+
private DateTime dt = DateTime.Now;
1201+
private double number = 1999.69;
1202+
}
1203+
```
1204+
1205+
Use the `CultureExample1` component shown in the [Demonstration component](#demonstration-component) section to study how globalization works for a component that inherits the global Auto render mode. Add the `CultureExample1` component to the `.Client` project's `Pages` folder.
1206+
1207+
Add the `CultureClient`, `CultureServer`, and `CultureExample1` components to the sidebar navigation in `Layout/NavMenu.razor`:
1208+
1209+
```razor
1210+
<div class="nav-item px-3">
1211+
<NavLink class="nav-link" href="culture-server">
1212+
<span class="bi bi-list-nested-nav-menu" aria-hidden="true"></span> Culture (Server)
1213+
</NavLink>
1214+
</div>
1215+
<div class="nav-item px-3">
1216+
<NavLink class="nav-link" href="culture-client">
1217+
<span class="bi bi-list-nested-nav-menu" aria-hidden="true"></span> Culture (Client)
1218+
</NavLink>
1219+
</div>
1220+
<div class="nav-item px-3">
1221+
<NavLink class="nav-link" href="culture-example-1">
1222+
<span class="bi bi-list-nested-nav-menu" aria-hidden="true"></span> Culture (Auto)
1223+
</NavLink>
1224+
</div>
1225+
```
1226+
11361227
### Server project updates
11371228

11381229
Add the [`Microsoft.Extensions.Localization`](https://www.nuget.org/packages/Microsoft.Extensions.Localization) package to the server project.
@@ -1253,89 +1344,9 @@ public class CultureController : Controller
12531344
> [!WARNING]
12541345
> Use the <xref:Microsoft.AspNetCore.Mvc.ControllerBase.LocalRedirect%2A> action result, as shown in the preceding example, to prevent open redirect attacks. For more information, see <xref:security/preventing-open-redirects>.
12551346
1256-
Add the `CultureSelector` component to the `MainLayout` component. Place the following markup inside the closing `</main>` tag in the `Components/Layout/MainLayout.razor` file:
1257-
1258-
```razor
1259-
<article class="bottom-row px-4">
1260-
<CultureSelector @rendermode="InteractiveAuto" />
1261-
</article>
1262-
```
1263-
1264-
Use the `CultureExample1` component shown in the [Demonstration component](#demonstration-component) section to study how the preceding example works.
1265-
1266-
In the server project, place the following `CultureServer` component to study how globalization works for SSR components.
1267-
1268-
`Components/Pages/CultureServer.razor`:
1269-
1270-
```razor
1271-
@page "/culture-server"
1272-
@rendermode InteractiveServer
1273-
@using System.Globalization
1274-
1275-
<PageTitle>Culture Server</PageTitle>
1276-
1277-
<h1>Culture Server</h1>
1278-
1279-
<ul>
1280-
<li><b>CurrentCulture</b>: @CultureInfo.CurrentCulture</li>
1281-
<li><b>CurrentUICulture</b>: @CultureInfo.CurrentUICulture</li>
1282-
</ul>
1283-
1284-
<h2>Rendered values</h2>
1285-
1286-
<ul>
1287-
<li><b>Date</b>: @dt</li>
1288-
<li><b>Number</b>: @number.ToString("N2")</li>
1289-
</ul>
1290-
1291-
<h2><code>&lt;input&gt;</code> elements that don't set a <code>type</code></h2>
1292-
1293-
<p>
1294-
The following <code>&lt;input&gt;</code> elements use
1295-
<code>CultureInfo.CurrentCulture</code>.
1296-
</p>
1297-
1298-
<ul>
1299-
<li><label><b>Date:</b> <input @bind="dt" /></label></li>
1300-
<li><label><b>Number:</b> <input @bind="number" /></label></li>
1301-
</ul>
1302-
1303-
<h2><code>&lt;input&gt;</code> elements that set a <code>type</code></h2>
1304-
1305-
<p>
1306-
The following <code>&lt;input&gt;</code> elements use
1307-
<code>CultureInfo.InvariantCulture</code>.
1308-
</p>
1309-
1310-
<ul>
1311-
<li><label><b>Date:</b> <input type="date" @bind="dt" /></label></li>
1312-
<li><label><b>Number:</b> <input type="number" @bind="number" /></label></li>
1313-
</ul>
1314-
1315-
@code {
1316-
private DateTime dt = DateTime.Now;
1317-
private double number = 1999.69;
1318-
}
1319-
```
1320-
1321-
Add both the `CultureClient` and `CultureServer` components to the sidebar navigation in `Components/Layout/NavMenu.razor`:
1322-
1323-
```razor
1324-
<div class="nav-item px-3">
1325-
<NavLink class="nav-link" href="culture-server">
1326-
<span class="bi bi-list-nested-nav-menu" aria-hidden="true"></span> Culture (Server)
1327-
</NavLink>
1328-
</div>
1329-
<div class="nav-item px-3">
1330-
<NavLink class="nav-link" href="culture-client">
1331-
<span class="bi bi-list-nested-nav-menu" aria-hidden="true"></span> Culture (Client)
1332-
</NavLink>
1333-
</div>
1334-
```
1335-
13361347
### Interactive Auto components
13371348

1338-
The guidance in this section also works for components that adopt the Interactive Auto render mode:
1349+
The guidance in this section also works for components in apps that adopt per-page/component rendering and specify the Interactive Auto render mode:
13391350

13401351
```razor
13411352
@rendermode InteractiveAuto

aspnetcore/blazor/security/additional-scenarios.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,14 @@ This article explains how to configure server-side Blazor for additional securit
2121

2222
:::moniker range=">= aspnetcore-8.0"
2323

24-
Updating this section for Blazor Web Apps is pending [Update section on passing tokens in Blazor Web Apps (`dotnet/AspNetCore.Docs` #31691)](https://github.com/dotnet/AspNetCore.Docs/issues/31691). For more information, see [Problem providing Access Token to HttpClient in Interactive Server mode (`dotnet/aspnetcore` #52390)](https://github.com/dotnet/aspnetcore/issues/52390).
24+
For Blazor Web Apps, guidance on how to pass tokens to Razor components should be [addressed in the documentation (`dotnet/AspNetCore.Docs` #31691)](https://github.com/dotnet/AspNetCore.Docs/issues/31691) in 2025 for a preview release of .NET 10.
2525

26-
For Blazor Server, view the [7.0 version of this article section](xref:blazor/security/additional-scenarios?view=aspnetcore-7.0#pass-tokens-to-a-server-side-blazor-app).
26+
For more information, see the following issues:
27+
28+
* [Access `AuthenticationStateProvider` in outgoing request middleware (`dotnet/aspnetcore` #52379)](https://github.com/dotnet/aspnetcore/issues/52379): This is the current issue to address passing tokens in Blazor Web Apps, currently scheduled for .NET 10 (late 2025).
29+
* [Problem providing Access Token to HttpClient in Interactive Server mode (`dotnet/aspnetcore` #52390)](https://github.com/dotnet/aspnetcore/issues/52390): This issue was closed as a duplicate of the preceding issue, but it contains helpful discussion and potential workaround strategies.
30+
31+
For Blazor Server, view the [7.0 version of this article section](xref:blazor/security/additional-scenarios?view=aspnetcore-7.0&preserve-view=true#pass-tokens-to-a-server-side-blazor-app).
2732

2833
<!--
2934
Tokens available outside of the Razor components in a Blazor Web App can be passed to components with the approach described in this section. The example in this section focuses on passing access and refresh tokens, but the approach is valid for other HTTP context state provided by <xref:Microsoft.AspNetCore.Http.HttpContext>.

aspnetcore/tutorials/first-mvc-app/details.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ uid: tutorials/first-mvc-app/details
1212

1313
[!INCLUDE[](~/includes/not-latest-version.md)]
1414

15-
By [Rick Anderson](https://twitter.com/RickAndMSFT) and Bryan Kaplan 2023 JHF trail
15+
By [Rick Anderson](https://twitter.com/RickAndMSFT)
1616

1717
:::moniker range=">= aspnetcore-9.0"
1818

0 commit comments

Comments
 (0)