I have created an application for automated form filling in a website.Basically i have to through 2 pages Login page and then the form filling page.Instead of going through two different pages,two times,I have prefered navigating the second page itself.That way if i am not logged in, the login page automatically comes up and then after filling in my credentials it auto redirects me to my page.

Now the problem is sometimes some sites dont redirect,so to deal with it I kept a timer for this purpose.After 6 secs after the login page I forcibly navigate to the second page via wb.navigate("http://abc.com/page2.htm")

Sometimes randomly,it again takes me to the login page although it previously shows I am logged in.....

I tried finding the solution to this but everywhere i found some answers of how to maintain session between 2 new windows.I have only ONE IE mshtml WEBBROWSER I am navigating all sites through that.

Now what could be the problem???
It seems as if the session is breaking when i forcibly navigate the second time,even though i am using one webbrowser.Moreover sometimes it works,sometime it doesnt

Part of my code

VB2008 Code:
  1. wb.Navigate(CPath)                      '1st  page navigation
  2.  
  3. WaitTillLoad()
  4.  
  5. If LoginPresent Or LoginPresent1 Or LoginPresent2 Or LoginPresent3 Then
  6.                         DirectCast(GetCurrentWebForm(index1).item(Username), mshtml.HTMLInputElement).value = TextBox1.Text
  7.                         DirectCast(GetCurrentWebForm(index1).item(Password), mshtml.HTMLInputElement).value = TextBox2.Text
  8.                         If RememberMe <> "" Then
  9.                             DirectCast(GetCurrentWebForm(index1).item(RememberMe, 0), mshtml.HTMLOptionButtonElement).checked = True
  10.                         End If
  11.                         If Login <> "" Then
  12.                             DirectCast(GetCurrentWebForm(index1).item(Login, 0), mshtml.HTMLButtonElement).click()
  13.                         Else
  14.                             GetCurrentWebForm(index1).submit()
  15.                         End If
  16.  
  17.  
  18.                         pause(5000)                                 'Waiting 5secs to redirect
  19.                         wb.Navigate(CPath)           'Redirecting to 2nd page forcibly irrespective it redirected succesfully or not
  20.                         WaitTillLoad()
  21.                     End If

Anyone has better logic,please contribute