Skip to content

Commit 8a6c821

Browse files
authored
Update globalization-localization.md (#20239)
1 parent e70df78 commit 8a6c821

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

aspnetcore/blazor/globalization-localization.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,19 @@ Localization is handled by the app in the following sequence of events:
149149
1. The Localization Middleware reads the cookie and assigns the culture.
150150
1. The Blazor Server session begins with the correct culture.
151151

152+
When working with a <xref:Microsoft.AspNetCore.Mvc.Razor.RazorPage>, use the <xref:Microsoft.AspNetCore.Mvc.Razor.RazorPage.Context> property:
153+
154+
```razor
155+
@{
156+
this.Context.Response.Cookies.Append(
157+
CookieRequestCultureProvider.DefaultCookieName,
158+
CookieRequestCultureProvider.MakeCookieValue(
159+
new RequestCulture(
160+
CultureInfo.CurrentCulture,
161+
CultureInfo.CurrentUICulture)));
162+
}
163+
```
164+
152165
#### Provide UI to choose the culture
153166

154167
To provide UI to allow a user to select a culture, a *redirect-based approach* is recommended. The process is similar to what happens in a web app when a user attempts to access a secure resource. The user is redirected to a sign-in page and then redirected back to the original resource.

0 commit comments

Comments
 (0)