在Awesomium中缓存Cookie

时间:2014-10-25 19:08:10

标签: winforms awesomium

设置:

我正在构建一个MDI应用程序。我调用的其中一个子窗体是使用Awesomium API的基本Web浏览器。

参考:BrowserControl.cs

public partial class BrowserControl : UserControl
{
    public BrowserControl()
    {
        InitializeComponent();
    }

    private void OnControlLoad(object sender, EventArgs e)
    {
        String w3DataPath = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + "\\HttpAgent";
        if (!Directory.Exists(w3DataPath))
        {
            Directory.CreateDirectory(w3DataPath);
        }
        var webSession = WebCore.CreateWebSession(w3DataPath, WebPreferences.Default);
        webControl.WebSession = webSession;
    }

    private void OnBackButtonClick(object sender, EventArgs e)
    {
        this.webControl.GoBack();
    }

    private void OnFwdButtonClick(object sender, EventArgs e)
    {
        this.webControl.GoForward();
    }

    private void OnReloadButtonClick(object sender, EventArgs e)
    {
        this.webControl.Reload(true);
    }

    private void OnStopButtonClick(object sender, EventArgs e)
    {
        this.webControl.Stop();
    }

    private void OnHomeButtonClick(object sender, EventArgs e)
    {
        this.webControl.GoToHome();
    }

    private void OnSearchButtonClick(object sender, EventArgs e)
    {
        String urlString = String.Format("https://www.google.com/#q={0}", HttpUtility.UrlEncode(this.SearchBox.Text));
        this.webControl.Source = new System.Uri(urlString);

    }

    private void OnLoadingFrame(object sender, Awesomium.Core.LoadingFrameEventArgs e)
    {
        this.BrowserStatus.Text = "Loading " + e.Url;
    }

    private void OnLoadingComplete(object sender, Awesomium.Core.FrameEventArgs e)
    {
        this.BrowserStatus.Text = "Document Ready";
    }

    private void OnLoadingFailure(object sender, Awesomium.Core.LoadingFrameFailedEventArgs e)
    {
        this.BrowserStatus.Text = e.ErrorDescription;
    }
}

问题:功能上浏览器运行正常;但是,它不会在本地缓存任何持久数据。请注意,我已使用Awesomium DataPath对象建立了有效的WebSession,如上述方法所示OnControlLoad()

就我定义的路径的有效性而言 - 我已经确认它确实存在于磁盘上,甚至看起来Awesomium WebSession添加了一个名为" cache"的子目录。不幸的是,我在网络会话中获得的cookie都没有在本地保存。实际上 - 没有任何东西被缓存。我故意登录到我知道已设置cookie的网站后,我定义的HttpAgent目录和WebSession对象定义的缓存目录都是空的。

非常感谢任何见解或帮助。谢谢

1 个答案:

答案 0 :(得分:0)

我不确定它是否有帮助,但尝试“正确”关闭Awesomium:处置WebControls,WebSession,调用WebCore.Shutdown()