.Net WebBrowser控件 [英] .Net WebBrowser Control

查看:84
本文介绍了.Net WebBrowser控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



.Net WebBrowser控件有一个奇怪的问题.我正在尝试删除Facebook cookie,然后处置WebBrowser控件,以便可以从内存中释放cookie,然后再次重新初始化WebBrowser控件,以便它们重新登录到facebook.

它不起作用.如果我关闭应用程序并执行此操作,它将起作用.

这是我正在使用的代码(是的,它看起来并不漂亮):

Hi,

I have a strange problem with the .Net WebBrowser control. I''m trying to delete facebook cookies and then dispose the WebBrowser control so that the cookies might be released from the memory and then reinitialize the WebBrowser control again in order for them to relogin to facebook.

It''s not working. If I close the app and do that, it works.

Here''s the code (yes, it doesn''t look preety) I''m using:

Private Sub ReinitializeBrowser()
        '_instance = New FrmBrowser()
        Dim uri As System.Uri = WebBrowser1.Url
        Dim point As Point = WebBrowser1.Location
        Dim size As Size = WebBrowser1.Size
        If Not (Me.WebBrowser1 Is Nothing) Then
            Me.WebBrowser1.Dispose()
            Me.Controls.Remove(Me.WebBrowser1)
        End If
        WebBrowser1 = New System.Windows.Forms.WebBrowser
        Me.WebBrowser1.Location = point
        Me.WebBrowser1.MinimumSize = New System.Drawing.Size(20, 20)
        Me.WebBrowser1.Name = "WebBrowser1"
        Me.WebBrowser1.ScrollBarsEnabled = False
        Me.WebBrowser1.Size = size
        Me.WebBrowser1.TabIndex = 2
        AddHandler Me.WebBrowser1.Navigating, AddressOf WebBrowser1_Navigating
        AddHandler Me.WebBrowser1.NewWindow, AddressOf WebBrowser1_NewWindow
        Me.Controls.Add(Me.WebBrowser1)
        Browse(strURL)
    End Sub


Public Function ResetBrowser() As Boolean
        Dim IsFBCookieDeleted As Boolean = False
        Dim theCookies() As String = System.IO.Directory.GetFiles(Environment.GetFolderPath(Environment.SpecialFolder.Cookies))
        For Each currentFile As String In theCookies
            Try
                If (currentFile.ToString.Contains("@facebook")) Then
                    IsFBCookieDeleted = True
                    System.IO.File.Delete(currentFile)
                End If
            Catch ex As Exception
            End Try
        Next
        If (IsFBCookieDeleted) Then
            FrmBrowser.Instance.ReinitializeBrowser()
            Return True
        Else
            Return False
        End If
    End Function



任何帮助将不胜感激.

谢谢,

Sudeep



Any help would be really appreciated.

Thanks,

Sudeep

推荐答案

对于初学者,请尝试查看删除文件时是否遇到异常.我的猜测是您可能会遇到这种情况.
For starters, try seeing if you are getting exceptions when deleting the files. My guess is that you may be experiencing this.


这篇关于.Net WebBrowser控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆