C# 从应用程序启动本机webbrowser时出现访问冲突异常

C# 从应用程序启动本机webbrowser时出现访问冲突异常,c#,windows-8,winrt-xaml,windows-applications,windows-8.1,C#,Windows 8,Winrt Xaml,Windows Applications,Windows 8.1,在C#中的WinRT应用程序中,我有一个用于设置的userControl,其中包含打开本地html文件的webview。我用javascript代码截取这个html文件上的链接,以启动本机webbrowser。当我这样做时,本机webbrowser会正确显示链接,但我的应用程序同时崩溃,出现“访问冲突”异常 以下是我的UserControl的代码: public sealed partial class SimpleSettingsNarrow : UserControl { publi

在C#中的WinRT应用程序中,我有一个用于设置的userControl,其中包含打开本地html文件的webview。我用javascript代码截取这个html文件上的链接,以启动本机webbrowser。当我这样做时,本机webbrowser会正确显示链接,但我的应用程序同时崩溃,出现“访问冲突”异常

以下是我的UserControl的代码:

public sealed partial class SimpleSettingsNarrow : UserControl
{
    public SimpleSettingsNarrow()
    {
        this.InitializeComponent();
    }

    private void ConditionWB_Loaded_1(object sender, RoutedEventArgs e)
    {
        ConditionWB.ScriptNotify += ConditionWB_ScriptNotify;
        ConditionWB.AllowedScriptNotifyUris = WebView.AnyScriptNotifyUri;
        ConditionWB.Navigate(new Uri("ms-appx-web:///Assets/testWebview.html"));
    }
    private async void ConditionWB_ScriptNotify(object sender, NotifyEventArgs e)
    {  
        await Windows.System.Launcher.LaunchUriAsync(new Uri(e.Value));
    }

}
下面是xaml代码:

<UserControl
x:Class="MyNameSpace.SimpleSettingsNarrow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:MyNameSpace"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="768"
d:DesignWidth="692">
<UserControl.Resources>

</UserControl.Resources>
<Border BorderBrush="Black" BorderThickness="1,0,0,0">
    <Grid Background="White" VerticalAlignment="Stretch">
        <!-- Root grid definition -->
        <Grid.RowDefinitions>
            <RowDefinition Height="80" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>

        <!-- Header area for panel -->
        <Grid Background="White" Grid.Row="0">

            <Grid Margin="40,32,17,13">

                <Grid.Transitions>
                    <TransitionCollection>
                        <EntranceThemeTransition FromHorizontalOffset="50" />
                    </TransitionCollection>
                </Grid.Transitions>

                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="30" />
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition />
                </Grid.ColumnDefinitions>

                <TextBlock Margin="10,0,0,0" Grid.Column="1" FontFamily="Segoe UI" FontWeight="Normal" FontSize="24.6667" Text="Déclaration de confidentialité" Foreground="Black" TextWrapping="Wrap" HorizontalAlignment="Left" />



            </Grid>
        </Grid>
        <ScrollViewer Grid.Row="1" Margin="20,20,0,20" Padding="0,0,20,0">
            <WebView x:Name="ConditionWB" Loaded="ConditionWB_Loaded_1"></WebView>

        </ScrollViewer>


    </Grid>
</Border>
</UserControl>

testWebview.html文件包含:

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
 <html xml:lang="fr" xmlns="http://www.w3.org/1999/xhtml">

 <head>
 </head>
 <body>
 test
 <a href="javascript:window.external.notify('http://www.google.fr')">google</a>


 </body>
 </html>

测验
你知道它为什么会这样崩溃吗


非常感谢

您必须使用Windows 8.1

在Windows 8.1中,不允许使用AllowedScriptNotifyURI,而应在项目“Package.appxmanifest”的“内容URI”中输入URL

注意:给定URL必须是“https”(http将不起作用)