Skip to content

Commit 56f0ff2

Browse files
Copilotjfversluis
andcommitted
Extract WebView2 Program Files warning into reusable include snippet
Co-authored-by: jfversluis <[email protected]>
1 parent 6831635 commit 56f0ff2

File tree

4 files changed

+19
-33
lines changed

4 files changed

+19
-33
lines changed

docs/user-interface/controls/blazorwebview.md

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,7 @@ Browser developer tools can be used to inspect .NET MAUI Blazor apps. For more i
3333
> [!NOTE]
3434
> While Visual Studio installs all the required tooling to develop .NET MAUI Blazor apps, end users of .NET MAUI Blazor apps on Windows must install the [WebView2](https://developer.microsoft.com/microsoft-edge/webview2/) runtime.
3535
36-
> [!WARNING]
37-
> On Windows, apps using <xref:Microsoft.AspNetCore.Components.WebView.Maui.BlazorWebView> that are installed to the `Program Files` directory may fail to render content properly. This occurs because WebView2 attempts to write its cache and user data files to the app's installation directory, which has restricted write permissions in `Program Files`. To resolve this issue, set the `WEBVIEW2_USER_DATA_FOLDER` environment variable before the <xref:Microsoft.AspNetCore.Components.WebView.Maui.BlazorWebView> is initialized:
38-
>
39-
> ```csharp
40-
> #if WINDOWS
41-
> var userDataFolder = Path.Combine(FileSystem.AppDataDirectory, "WebView2");
42-
> Environment.SetEnvironmentVariable("WEBVIEW2_USER_DATA_FOLDER", userDataFolder);
43-
> #endif
44-
> ```
45-
>
46-
> Place this code in your `App.xaml.cs` constructor or in `Platforms\Windows\App.xaml.cs` before any <xref:Microsoft.AspNetCore.Components.WebView.Maui.BlazorWebView> is created. This directs WebView2 to use a writable location in the user's AppData directory instead of the restricted Program Files location.
36+
[!INCLUDE [WebView2 Program Files warning](includes/webview2-program-files-warning.md)]
4737

4838
For more information about Blazor Hybrid apps, see [ASP.NET Core Blazor Hybrid](/aspnet/core/blazor/hybrid).
4939

docs/user-interface/controls/hybridwebview.md

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,7 @@ The entire app, including the web content, is packaged and runs locally on a dev
3434
> [!IMPORTANT]
3535
> By default, the <xref:Microsoft.Maui.Controls.HybridWebView> control won't be available when full trimming or Native AOT is enabled. To change this behavior, see [Trimming feature switches](~/deployment/trimming.md#trimming-feature-switches).
3636
37-
> [!WARNING]
38-
> On Windows, apps using <xref:Microsoft.Maui.Controls.HybridWebView> that are installed to the `Program Files` directory may fail to render content properly. This occurs because WebView2 attempts to write its cache and user data files to the app's installation directory, which has restricted write permissions in `Program Files`. To resolve this issue, set the `WEBVIEW2_USER_DATA_FOLDER` environment variable before the <xref:Microsoft.Maui.Controls.HybridWebView> is initialized:
39-
>
40-
> ```csharp
41-
> #if WINDOWS
42-
> var userDataFolder = Path.Combine(FileSystem.AppDataDirectory, "WebView2");
43-
> Environment.SetEnvironmentVariable("WEBVIEW2_USER_DATA_FOLDER", userDataFolder);
44-
> #endif
45-
> ```
46-
>
47-
> Place this code in your `App.xaml.cs` constructor or in `Platforms\Windows\App.xaml.cs` before any <xref:Microsoft.Maui.Controls.HybridWebView> is created. This directs WebView2 to use a writable location in the user's AppData directory instead of the restricted Program Files location.
37+
[!INCLUDE [WebView2 Program Files warning](includes/webview2-program-files-warning.md)]
4838

4939
## Create a .NET MAUI HybridWebView app
5040

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
ms.topic: include
3+
ms.date: 09/19/2025
4+
---
5+
6+
> [!WARNING]
7+
> On Windows, apps using WebView2-based controls that are installed to the `Program Files` directory may fail to render content properly. This occurs because WebView2 attempts to write its cache and user data files to the app's installation directory, which has restricted write permissions in `Program Files`. To resolve this issue, set the `WEBVIEW2_USER_DATA_FOLDER` environment variable before any WebView control is initialized:
8+
>
9+
> ```csharp
10+
> #if WINDOWS
11+
> var userDataFolder = Path.Combine(FileSystem.AppDataDirectory, "WebView2");
12+
> Environment.SetEnvironmentVariable("WEBVIEW2_USER_DATA_FOLDER", userDataFolder);
13+
> #endif
14+
> ```
15+
>
16+
> Place this code in your `App.xaml.cs` constructor or in `Platforms\Windows\App.xaml.cs` before any WebView control is created. This directs WebView2 to use a writable location in the user's AppData directory instead of the restricted Program Files location.

docs/user-interface/controls/webview.md

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,7 @@ The `Source` property can be set to an `UrlWebViewSource` object or a `HtmlWebVi
4040
> [!IMPORTANT]
4141
> A <xref:Microsoft.Maui.Controls.WebView> must specify its <xref:Microsoft.Maui.Controls.VisualElement.HeightRequest> and <xref:Microsoft.Maui.Controls.VisualElement.WidthRequest> properties when contained in a <xref:Microsoft.Maui.Controls.HorizontalStackLayout>, <xref:Microsoft.Maui.Controls.StackLayout>, or <xref:Microsoft.Maui.Controls.VerticalStackLayout>. If you fail to specify these properties, the <xref:Microsoft.Maui.Controls.WebView> will not render.
4242
43-
> [!WARNING]
44-
> On Windows, apps using <xref:Microsoft.Maui.Controls.WebView> that are installed to the `Program Files` directory may fail to render content properly. This occurs because WebView2 attempts to write its cache and user data files to the app's installation directory, which has restricted write permissions in `Program Files`. To resolve this issue, set the `WEBVIEW2_USER_DATA_FOLDER` environment variable before the <xref:Microsoft.Maui.Controls.WebView> is initialized:
45-
>
46-
> ```csharp
47-
> #if WINDOWS
48-
> var userDataFolder = Path.Combine(FileSystem.AppDataDirectory, "WebView2");
49-
> Environment.SetEnvironmentVariable("WEBVIEW2_USER_DATA_FOLDER", userDataFolder);
50-
> #endif
51-
> ```
52-
>
53-
> Place this code in your `App.xaml.cs` constructor or in `Platforms\Windows\App.xaml.cs` before any <xref:Microsoft.Maui.Controls.WebView> is created. This directs WebView2 to use a writable location in the user's AppData directory instead of the restricted Program Files location.
43+
[!INCLUDE [WebView2 Program Files warning](includes/webview2-program-files-warning.md)]
5444

5545
## Display a web page
5646

0 commit comments

Comments
 (0)