0

OutlookアドインでWebBrowserの.Urlプロパティを取得しようとすると、「アクセス違反」ランタイムエラーが発生します。これを乗り越える方法について助けが必要です。調査によると、「FullTrust」権限セットを設定する必要があるかもしれませんが、それを試しても成功しませんでした。

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;
using System.Security;
using System.Security.Permissions;

namespace MyAddin1
{

public partial class authForm : Form
{

    public string currentUrl;

    public authForm()
    {
        InitializeComponent();
    }


    private void formLoaded(object sender, EventArgs e)
    {
        WebBrowser browser = new WebBrowser();
        browser.Location = new System.Drawing.Point(0, 0);
        browser.Width = 870;
        browser.Height = 510;
        browser.Navigate("https://www.yammer.com/dialog/oauth?client_id=<redacted>&response_type=token");
        browser.Show();

        //runtime error occurs on following line
        currentUrl = browser.Url.ToString();


        browser.Url = new Uri("http://www.yahoo.com");

        browser.Navigated += new WebBrowserNavigatedEventHandler(checkForToken);


        this.Controls.Add(browser);
    }

    private void checkForToken(object sender, EventArgs e)
    {
        MessageBox.Show(currentUrl);
    }




}

}

4

1 に答える 1

1

browser.Urlは最初は null です。以下のようにコードを変更してください。

if (browser.Url != null)
{
    currentUrl = browser.Url.ToString();
}
于 2012-12-28T18:19:59.543 に答える