Microsoft.Toolkit.Win32
Microsoft.Toolkit.Win32 copied to clipboard
Cannot navigate to localhost
I'm submitting a...
- Bug report (I searched for similar issues and did not find one)
Current behavior
While navigating to localhost site with IsPrivateNetworkClientServerCapabilityEnabled set to true, nothing happened, blank displaying with no DOMContentLoaded raised.
It's similar like set IsPrivateNetworkClientServerCapabilityEnabled to true between BeginInit and EndInit in Winform. Reported here.
Expected behavior
Works like Edge or other web browsers.
Minimal reproduction of the problem with instructions
webView1.Navigate("http://localhost/test/");
Environment
Nuget Package(s): Microsoft.Toolkit.Wpf.UI.Controls.WebView 5.1.1
Package Version(s):
Windows 10 Build Number:
- [x] Insider Build (build number: 18912)
App min and target version:
- [x] Insider Build (18912)
Device form factor:
- [x] Desktop
Visual Studio
- [x] 2019
NetFx 4.8
Codes for test: EdgeTest.zip
As a workaround you can execute this command as an administrator. This will allow EdgeHTML to access localhost URLs.
checknetisolation LoopbackExempt -a -n="Microsoft.Win32WebViewHost_cw5n1h2txyewy"
The program needs to be run only once. It is a clutch, but I so far have not found a better solution.
For completeness, to make your app do it on its own call this method when your app starts:
private static void AllowLoopBack()
{
if (runOnce)
{
return;
}
runOnce = true;
new Process
{
StartInfo = new ProcessStartInfo
{
WindowStyle = ProcessWindowStyle.Hidden,
UseShellExecute = true,
FileName = "cmd.exe",
Arguments =
"/C checknetisolation LoopbackExempt -a -n=\"Microsoft.Win32WebViewHost_cw5n1h2txyewy\"",
Verb = "runas"
}
}.Start();
}