Exemplo n.º 1
0
        private void webView_NavigationStarting(object sender, Microsoft.Web.WebView2.Core.CoreWebView2NavigationStartingEventArgs e)
        {
            //在页面开始前注入脚本并执行
            String uri = e.Uri;

            if (!uri.StartsWith("https://"))
            {
                //立即执行脚本
                webView.CoreWebView2.ExecuteScriptAsync($"alert('{uri} is not safe, try an https link')");
                e.Cancel = true;
            }
        }
        private async void webView_NavigationStarting(WebView2 sender, Microsoft.Web.WebView2.Core.CoreWebView2NavigationStartingEventArgs args)
        {
            var url = args.Uri.ToString();

            if (url.Contains("void/callback"))
            {
                webView.Visibility = Visibility.Collapsed;
                await CompleteLogin(url);

                await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                {
                    UpdateMenuButtons();
                    this.Frame.Navigate(typeof(HomePage));
                });
            }
        }
Exemplo n.º 3
0
 private void Wv2_NavigationStarting(object sender, Microsoft.Web.WebView2.Core.CoreWebView2NavigationStartingEventArgs e)
 {
     e.Cancel = IsDisallowed(e.Uri);
 }
Exemplo n.º 4
0
 private void CoreWebView2_FrameNavigationStarting(object sender, Microsoft.Web.WebView2.Core.CoreWebView2NavigationStartingEventArgs e)
 {
     //System.Diagnostics.Debug.WriteLine($"FVS {e.Uri}");
     e.Cancel = IsDisallowed(e.Uri);
 }
Exemplo n.º 5
0
        private void WebView_NavigationStarting(object sender, Microsoft.Web.WebView2.Core.CoreWebView2NavigationStartingEventArgs e)
        {
            if (e.Uri.StartsWith(RETURN_URL))
            {
                try
                {
                    var webView = sender as WebView2;

                    // Split URL by #
                    var splitted = e.Uri.Split('?');
                    if (splitted.Count() != 2)
                    {
                        throw new Exception("Return URL doesn't contain ?. Can't read response values.");
                    }

                    // Parse query params
                    var queryParams = HttpUtility.ParseQueryString(splitted[1]);

                    // Check if it's error
                    if (queryParams.AllKeys.Contains("error"))
                    {
                        // Check if back button was clicked
                        if (queryParams.AllKeys.Contains("error_subcode") && queryParams["error_subcode"] == "cancel")
                        {
                            e.Cancel = true;

                            if (!IsProVersion())
                            {
                                _webUIForm?.Navigate(WebUIForm.LOCAL_WEB_UI_URL + "login/intro");
                            }
                            else
                            {
                                Close();
                            }

                            return;
                        }
                        else
                        {
                            var errorMessage = "Login failed. Server returned error.";
                            if (queryParams.AllKeys.Contains("error_description") && !String.IsNullOrWhiteSpace(queryParams["error_description"]))
                            {
                                errorMessage = HttpUtility.UrlDecode(queryParams["error_description"]);
                            }

                            throw new Exception(errorMessage);
                        }
                    }

                    // Extract token
                    if (!queryParams.AllKeys.Contains("code") || String.IsNullOrWhiteSpace(queryParams["code"]))
                    {
                        throw new Exception("Code not found in response parameters.");
                    }

                    var code = queryParams["code"];

                    // Redeem code for access token
                    var token = Task.Run(() => RedeemCodeForAuthToken(code)).Result;

                    // Store token
                    UserService.GetInstance()
                    .SetAccessToken(token.AccessToken, token.RefreshToken, DateTime.Now.AddSeconds(token.ExpiresIn - 30));

                    // Close window
                    Close();
                }
                catch (Exception ex)
                {
                    var errorMessage = ex.Message;
                    if (ex is AggregateException aggEx)
                    {
                        errorMessage = String.Join(Environment.NewLine, aggEx.InnerExceptions.Select(o => o.Message));
                    }

                    MessageBox.Show(errorMessage, "Login error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                finally
                {
                    // If callback URL is loaded, always cancel request
                    e.Cancel = true;
                }
            }
        }
Exemplo n.º 6
0
 private void WebView_NavigationStarting(object sender, Microsoft.Web.WebView2.Core.CoreWebView2NavigationStartingEventArgs e)
 {
     //webView.CoreWebView2.Settings.IsZoomControlEnabled = false;
 }
Exemplo n.º 7
0
        private void webView_NavigationStarting(object sender, Microsoft.Web.WebView2.Core.CoreWebView2NavigationStartingEventArgs e)
        {
            Console.WriteLine("webView_NavigationStarting");

            Console.WriteLine(e.Uri);
        }