Skip to content

Commit 6831635

Browse files
Copilotjfversluis
andcommitted
Add Windows Program Files warning for WebView2/BlazorWebView/HybridWebView
Co-authored-by: jfversluis <939291+jfversluis@users.noreply.github.com>
1 parent 3f307e9 commit 6831635

File tree

3 files changed

+39
-3
lines changed

3 files changed

+39
-3
lines changed

docs/user-interface/controls/blazorwebview.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: "Host a Blazor web app in a .NET MAUI app using BlazorWebView"
33
description: "The .NET MAUI BlazorWebView control enables you to host a Blazor web app in your .NET MAUI app, and integrate the app with device features."
4-
ms.date: 05/13/2025
4+
ms.date: 09/19/2025
55
---
66

77
# Host a Blazor web app in a .NET MAUI app using BlazorWebView
@@ -33,6 +33,18 @@ 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.
47+
3648
For more information about Blazor Hybrid apps, see [ASP.NET Core Blazor Hybrid](/aspnet/core/blazor/hybrid).
3749
3850
## Create a .NET MAUI Blazor app

docs/user-interface/controls/hybridwebview.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: HybridWebView
33
description: Learn how to use a HybridWebView to host HTML/JS/CSS content in a WebView, and communicate between that content and .NET.
44
ms.topic: concept-article
5-
ms.date: 08/20/2025
5+
ms.date: 09/19/2025
66
monikerRange: ">=net-maui-9.0"
77

88
#customer intent: As a developer, I want to host HTML/JS/CSS content in a web view so that I can publish the web app as a mobile app.
@@ -34,6 +34,18 @@ 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.
48+
3749
## Create a .NET MAUI HybridWebView app
3850
3951
To create a .NET MAUI app with a <xref:Microsoft.Maui.Controls.HybridWebView>:

docs/user-interface/controls/webview.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: "WebView"
33
description: "This article explains how to use the .NET MAUI WebView to display remote web pages, local HTML files, and HTML strings."
4-
ms.date: 08/19/2025
4+
ms.date: 09/19/2025
55
zone_pivot_groups: devices-platforms
66
---
77

@@ -40,6 +40,18 @@ 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.
54+
4355
## Display a web page
4456
4557
To display a remote web page, set the `Source` property to a `string` that specifies the URI:

0 commit comments

Comments
 (0)