Click here to Skip to main content
15,923,557 members
Home / Discussions / Visual Basic
   

Visual Basic

 
AnswerRe: DataGridView column sort using different column value Pin
Mycroft Holmes13-Nov-08 16:00
professionalMycroft Holmes13-Nov-08 16:00 
GeneralRe: DataGridView column sort using different column value Pin
CAN Coder14-Nov-08 6:37
CAN Coder14-Nov-08 6:37 
GeneralRe: DataGridView column sort using different column value Pin
Mycroft Holmes14-Nov-08 16:41
professionalMycroft Holmes14-Nov-08 16:41 
GeneralRe: DataGridView column sort using different column value Pin
CAN Coder15-Nov-08 1:26
CAN Coder15-Nov-08 1:26 
Question"{ " as a string in VB Pin
papy-boom13-Nov-08 5:15
papy-boom13-Nov-08 5:15 
AnswerRe: "{ " as a string in VB Pin
Dave Kreskowiak13-Nov-08 5:30
mveDave Kreskowiak13-Nov-08 5:30 
AnswerRe: "{ " as a string in VB Pin
sph3rex13-Nov-08 7:24
sph3rex13-Nov-08 7:24 
QuestionWebBrowser control, HTTPS SSL certificate security dialog Pin
akuma609913-Nov-08 4:49
akuma609913-Nov-08 4:49 
I'm writing a util that uses a hidden webbrowser control to traverse through a few .aspx pages. These are through an SSL enabled site. I want to accept the certificate and or install it locally instead of the end user clicking on "yes" to accept it. I've googled for quite some time and found 2 different methods. One for .NET 1.1 and .NET 2.0. I cannot get either to work. The dialog still pops up. I am trying to put this into a module. Here's what I have tried.

Imports System.Net
Imports System.Net.Security
Imports System.Security.Cryptography.X509Certificates
Imports System.Security.Policy




Module VWeb

    Dim WithEvents WB As New WebBrowser
    Dim ASPComplete As Integer = 0
    Dim LoginURI As New Uri("https://XXX.com/Login.aspx")
    Dim OpenCallsURI As New Uri("https://XXX.com/openCallReport.aspx")
    Dim MainPage As New Uri("https://XXX.com/Default.aspx")
    Dim TestTimer As New Timer()

Public Function LoginAsTech(ByVal UserID As String, ByVal Pass As String) As Boolean
        Dim MyDoc As New mshtml.HTMLDocument
        Dim DocElements As mshtml.IHTMLElementCollection = Nothing
        Dim LoginForm As mshtml.HTMLFormElement = Nothing

        ServicePointManager.ServerCertificateValidationCallback = New RemoteCertificateValidationCallback(AddressOf ValidateCertificate)
        
        ASPComplete = 0
        WB.Navigate(LoginURI)
        BrowserLoop()

        MyDoc = WB.Document.DomDocument
        DocElements = MyDoc.getElementsByTagName("input")
        For Each i As mshtml.IHTMLElement In DocElements

            Select Case i.name
                Case "seLogin$UserName"
                    i.value = UserID
                Case "seLogin$Password"
                    i.value = Pass
                Case Else
                    Exit Select
            End Select

            frmServiceCalls.txtOut.Text &= i.name & " : " & i.value & " : " & i.type & vbCrLf
        Next i
        'WB.Document.Forms("form1").InvokeMember("submit")


        LoginForm = MyDoc.forms.item("form1")
        LoginForm.item("seLogin$LoginButton").click()
        ASPComplete = 0
        BrowserLoop()



        MyDoc = WB.Document.DomDocument
        DocElements = MyDoc.getElementsByTagName("input")
        For Each j As mshtml.IHTMLElement In DocElements
            frmServiceCalls.txtOut.Text &= j.name & " : " & j.value & " : " & j.type & vbCrLf

        Next j

        frmServiceCalls.txtOut.Text &= vbCrLf & vbCrLf & WB.Url.AbsoluteUri & vbCrLf

        Return 1
    End Function

    Public Sub BrowserLoop()
        Do Until ASPComplete = 1
            Application.DoEvents()
        Loop

    End Sub



    Private Sub WB_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WB.DocumentCompleted
        ASPComplete = 1
        frmMain.tsProgress.Visible = False
        frmMain.lblProgress.Text = ""
    End Sub


    Private Sub WB_Navigating(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserNavigatingEventArgs) Handles WB.Navigating
        frmMain.tsProgress.Visible = True
        frmMain.lblProgress.Text = "Navagating"
    End Sub

    Public Sub WB_ProgressChanged(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserProgressChangedEventArgs) Handles WB.ProgressChanged
        frmMain.tsProgress.Maximum = Convert.ToInt32(e.MaximumProgress)
        frmMain.tsProgress.Value = Convert.ToInt32(e.CurrentProgress)
    End Sub

    Public Function ValidateCertificate(ByVal sender As Object, ByVal certificate As X509Certificate, ByVal chain As X509Chain, ByVal sslPolicyErrors As Security.SslPolicyErrors) As Boolean
        'Return True to force the certificate to be accepted.
        Return True
    End Function
End Module




Method 1 - This method is for the .NET 1.1 framework. I'm using 2.0. Tried it anyways with no luck.

frmMain_Load Event()
ServicePointManager.ServerCertificateValidationCallback = New CertPolicyOverride





Imports System.Net
Imports System.Security.Cryptography.X509Certificates

Public Class CertPolicyOverride
    Implements ICertificatePolicy

    Public Function CheckValidationResult(ByVal srvPoint As ServicePoint, ByVal cert As X509Certificate, ByVal request As WebRequest, _
    ByVal certificateProblem As Integer) As Boolean Implements ICertificatePolicy.CheckValidationResult
        'Return True to force the certificate to be accepted.
        Return True
    End Function
End Class






Method 2 - Tried putting ServicePointManager line in the frmMain_Load event, didn't work. Tried in the module before "navigating" call. Tested the same. I also tried ValidateCertificate in both frmMain and in the module as well.

ServicePointManager.ServerCertificateValidationCallback = New RemoteCertificateValidationCallback(AddressOf ValidateCertificate)

        
Public Function ValidateCertificate(ByVal sender As Object, ByVal certificate As X509Certificate, ByVal chain As X509Chain, ByVal sslPolicyErrors As Security.SslPolicyErrors) As Boolean
        'Return True to force the certificate to be accepted.
        Return True
    End Function



I've tried a few ways and I've been trying off and on for about 2 weeks. Finally came to the message boards for help. I'm starting to wonder if it has to do with the WebBrowser class. I was trying to stay away from WebRequest and HttpWebRequest. I find it really easy to process these web pages and javascript utilizing the WebBrowser control. I need to click a button or checkbox here and there and I would rather let the WebBrowser handle the background stuff like .aspx/javascript callbacks, realtime combo box updates etc... Things that are processed as you go. Any Takers??

Thank you,
Joe G.
AnswerRe: WebBrowser control, HTTPS SSL certificate security dialog Pin
sph3rex13-Nov-08 10:17
sph3rex13-Nov-08 10:17 
AnswerRe: WebBrowser control, HTTPS SSL certificate security dialog Pin
BimJeam15-Nov-08 3:56
BimJeam15-Nov-08 3:56 
GeneralRe: WebBrowser control, HTTPS SSL certificate security dialog Pin
akuma609916-Nov-08 17:34
akuma609916-Nov-08 17:34 
GeneralRe: WebBrowser control, HTTPS SSL certificate security dialog Pin
BimJeam23-Nov-08 12:13
BimJeam23-Nov-08 12:13 
QuestionModulo Checksum Claculation Pin
MatthysDT13-Nov-08 3:40
MatthysDT13-Nov-08 3:40 
AnswerRe: Modulo Checksum Claculation Pin
Dave Kreskowiak13-Nov-08 4:53
mveDave Kreskowiak13-Nov-08 4:53 
GeneralRe: Modulo Checksum Claculation Pin
MatthysDT13-Nov-08 20:44
MatthysDT13-Nov-08 20:44 
GeneralRe: Modulo Checksum Claculation Pin
Dave Kreskowiak14-Nov-08 16:17
mveDave Kreskowiak14-Nov-08 16:17 
GeneralRe: Modulo Checksum Claculation Pin
MatthysDT16-Nov-08 20:41
MatthysDT16-Nov-08 20:41 
AnswerRe: Modulo Checksum Claculation Pin
Rajesh Anuhya13-Nov-08 22:08
professionalRajesh Anuhya13-Nov-08 22:08 
GeneralRe: Modulo Checksum Claculation Pin
MatthysDT13-Nov-08 22:44
MatthysDT13-Nov-08 22:44 
GeneralRe: Modulo Checksum Claculation Pin
Rajesh Anuhya14-Nov-08 0:45
professionalRajesh Anuhya14-Nov-08 0:45 
QuestionOpen local programme from email (with link) Pin
Tom Deketelaere13-Nov-08 2:51
professionalTom Deketelaere13-Nov-08 2:51 
AnswerRe: Open local programme from email (with link) Pin
Jon_Boy13-Nov-08 4:17
Jon_Boy13-Nov-08 4:17 
GeneralRe: Open local programme from email (with link) Pin
Tom Deketelaere13-Nov-08 4:27
professionalTom Deketelaere13-Nov-08 4:27 
AnswerRe: Open local programme from email (with link) Pin
Dave Kreskowiak13-Nov-08 4:44
mveDave Kreskowiak13-Nov-08 4:44 
GeneralRe: Open local programme from email (with link) Pin
Tom Deketelaere13-Nov-08 4:56
professionalTom Deketelaere13-Nov-08 4:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.