Click here to Skip to main content
15,615,024 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
I am facing some issue with webbrowser control. I login to a site using webclient c#. Then at a point I show website in browser. So I grab cookie from webclient and set cookies to webbrowser using InternetSetCookie and then navigate to the page. What happens next is I get screen in webbrowser where I login but it logout immidiatly.
I dont understand why it is happening, I need help at this point.

I use this function to set value of cookie in webbrowser..



C#
[DllImport("wininet.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern bool InternetSetCookie(string url, string name, string data);

public static bool SetWinINETCookieString(string url, string name, string data)
{
      return InternetSetCookie(url, name, data);
}



C#
Here is where I get data from webclient object and make a new post in webbrowser control.



C#
System.Text.Encoding encoding = System.Text.Encoding.UTF8;
   byte[] byteArray = encoding.GetBytes(sPostParameter);
   string authHeader = oBankcl1.PAYMENT_PAGE_AUTH_HEADER1;

   InteropServicescl oInteropServicescl1 = new InteropServicescl();
   oInteropServicescl1.ChangeUserAgent("Mozilla/5.0 (Windows T 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.116 Safari/537.36");
   CookieCollection oCookieCollection = Cookiecl.GetAllCookies(webClient.CookieContainer);
   AddCookieFromCookieColl(oCookieCollection);

  this.wbWebbrowser.Navigate("https://www.abc.co.in/add/main.jsf", string.Empty, byteArray, authHeader);


C#
here i see my website in browser but it trigger logout url after 1 sec and gives login screen. i dont understand who trigger logout.

please help me on this.i need this thing . i have trie latest version of ie from this post http://stackoverflow.com/questions/17922308/use-latest-version-of-ie-in-webbrowser-control


What I have tried:

I grab cookie from webclient and set cookies to webbrowser using InternetSetCookie and then navigate to the page

see above
Posted
Updated 8-Aug-16 22:34pm
Comments
njammy 9-Aug-16 7:19am    
Have you checked if the cookie is expired or somehow invalid and causing the page to logout due to this?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900