Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/333.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
阻止C#中的WebBrowser控件在登录Windows Live时启动外部IE弹出窗口_C#_Webbrowser Control_Windows Live - Fatal编程技术网

阻止C#中的WebBrowser控件在登录Windows Live时启动外部IE弹出窗口

阻止C#中的WebBrowser控件在登录Windows Live时启动外部IE弹出窗口,c#,webbrowser-control,windows-live,C#,Webbrowser Control,Windows Live,这是Visual Studio 2012中的桌面C#应用程序 我需要使用C#中的WebBrowser控件来登录Windows Live实例,让该控件打开页面什么都不是,但登录让我头疼 我尝试了从谷歌收集到的4种不同的建议,但我没有正确登录 这就是我得到的: //FORM1 code //Added reference to 'Microsoft Internet Controls' using System; using System.Collections.Generic; using Sys

这是Visual Studio 2012中的桌面C#应用程序

我需要使用C#中的WebBrowser控件来登录Windows Live实例,让该控件打开页面什么都不是,但登录让我头疼

我尝试了从谷歌收集到的4种不同的建议,但我没有正确登录

这就是我得到的:

//FORM1 code
//Added reference to 'Microsoft Internet Controls'
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication3
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            webBrowser1.Url = new Uri("http://digitbot.com/live/");
        }
        SHDocVw.WebBrowser nativeBrowser;
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            nativeBrowser = (SHDocVw.WebBrowser)webBrowser1.ActiveXInstance;
            nativeBrowser.NewWindow2 += nativeBrowser_NewWindow2;
        }
        protected override void OnFormClosing(FormClosingEventArgs e)
        {
            nativeBrowser.NewWindow2 -= nativeBrowser_NewWindow2;
            base.OnFormClosing(e);
        }

        void nativeBrowser_NewWindow2(ref object ppDisp, ref bool Cancel)
        {
            var popup = new Form2();
            popup.Show(this);
            ppDisp = popup.Browser.ActiveXInstance;
        }
    }
}



//FORM2 code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication3
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }
        public WebBrowser Browser
        {
            get { return webBrowser1; }
        }
    }
}
这将在第二个窗口中启动登录弹出窗口,但不知何故,它似乎从未完成该过程

在浏览器中,按照上面代码中的链接应该可以让您登录,并且应该显示日历事件的原始JSON,后面是一个配置文件图片。我需要在WebBrowser控件中获得相同的结果


任何帮助都会很好,我被卡住了。

从来没有得到过我最初的工作方法,所以我切换到使用带有REST服务器端的WebClient和浏览器,因为我需要与注销的用户一起做一些事情

这是使用WPF在C#Windows 8端的基本设置:

static string client_id = "your-client-id";
static string client_secret = "your-client-secret";
static string accessTokenUrl = 
  String.Format(@"https://login.live.com/oauth20_token.srf?client_id={0}&client" + 
  @"_secret={1}&redirect_uri=https://login.live.com/oauth20_desktop.srf&grant_type" + 
  @"=authorization_code&code=", client_id, client_secret);
static string apiUrl = @"https://apis.live.net/v5.0/";
public Dictionary<string, string> tokenData = new Dictionary<string, string>(); 

这里有一个链接指向一个更详细的解释:

我从来没有得到过我最初的工作方法,所以我转而使用REST服务器端的WebClient和浏览器,因为我需要对注销的用户进行处理

这是使用WPF在C#Windows 8端的基本设置:

static string client_id = "your-client-id";
static string client_secret = "your-client-secret";
static string accessTokenUrl = 
  String.Format(@"https://login.live.com/oauth20_token.srf?client_id={0}&client" + 
  @"_secret={1}&redirect_uri=https://login.live.com/oauth20_desktop.srf&grant_type" + 
  @"=authorization_code&code=", client_id, client_secret);
static string apiUrl = @"https://apis.live.net/v5.0/";
public Dictionary<string, string> tokenData = new Dictionary<string, string>(); 

这里有一个链接指向更详细的解释:

是否显示登录弹出窗口?我不清楚您观察到的行为。弹出窗口显示,我可以输入登录详细信息,但我无法登录&我无法获得日历结果。这是Windows窗体应用程序还是WPF?它是Windows窗体应用程序,但如果有助于解决问题,我切换到WPF没有问题。是否显示登录弹出窗口?我不清楚您观察到的行为。弹出窗口显示,我可以输入登录详细信息,但我无法登录&我无法获得日历结果。这是Windows窗体应用程序还是WPF?这是Windows窗体应用程序,但如果WPF有助于解决问题,我切换到WPF没有问题。此示例应添加到msdn中!此示例应添加到msdn中!
<Window x:Class="WpfApplication3.BrowserWindow"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      Title="Sign In" Height="460" Width="423.881" 
      ShowInTaskbar="False" WindowStartupLocation="CenterScreen">
    <Grid>
        <WebBrowser Height="419" HorizontalAlignment="Left" 
           Name="webBrowser" VerticalAlignment="Top" 
           Width="406" LoadCompleted="webBrowser_LoadCompleted" />
    </Grid>
</Window>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Text.RegularExpressions;

namespace WpfApplication3

{
    public partial class BrowserWindow : Window
    {
        static string scope = "wl.signin wl.calendars wl.offline_access wl.contacts_calendars";
        static string client_id = "your-client-id";
        static Uri signInUrl = new Uri(String.Format(@"https://login.live.com/oauth20" + 
          @"_authorize.srf?client_id={0}&redirect_uri=https://login.live.com/" + 
          @"oauth20_desktop.srf&response_type=code&scope={1}", client_id, scope));
        MainWindow mainWindow = new MainWindow();

        public BrowserWindow()
        {
            InitializeComponent();
            webBrowser.Navigate(signInUrl);
        }

        private void webBrowser_LoadCompleted(object sender, System.Windows.Navigation.NavigationEventArgs e)
        {
            if (e.Uri.AbsoluteUri.Contains("code="))
            {
                if (App.Current.Properties.Contains("auth_code"))
                {
                    App.Current.Properties.Clear();
                }
                string auth_code = Regex.Split(e.Uri.AbsoluteUri, "code=")[1];
                App.Current.Properties.Add("auth_code", auth_code);
                this.Close();
            }
        }
    }
}