locked
Webbrowser control logout automatically after login RRS feed

  • Question

  • 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 am using webbrowser in window form application.
    I dont understand why it is happening, I need help at this point.

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

    [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); }

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

    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);

    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 . i have seen here are very talented developers are available.

    http://stackoverflow.com/questions/17922308/use-latest-version-of-ie-in-webbrowser-control

    • Edited by MrinalKumarJha Tuesday, August 9, 2016 8:53 AM
    • Moved by CoolDadTx Tuesday, August 9, 2016 2:14 PM Winforms related
    Monday, August 8, 2016 6:49 PM

Answers

  • Hi MrinalKumarJha,

    >>" i saw cookie in fiddler and cookie is being set properly."

    Please post your HTTP response message  after webclient request and HTTP request message from WebBrowser control for further discussion.

    I agree with @Christopher84, the issue is 90% caused by web server, because the rule is defined by web server.

    In addition, I suggest you use InternetSetCookieEx instead of InternetSetCookie. We could set the state of Cookie by dwFlags. For example, HTTPONLY or THIRD_PARTY.

    DWORD InternetSetCookieEx(
      _In_ LPCTSTR   lpszURL,
      _In_ LPCTSTR   lpszCookieName,
      _In_ LPCTSTR   lpszCookieData,
      _In_ DWORD     dwFlags,
      _In_ DWORD_PTR dwReserved
    );
    Best Regards,
    Li Wang

    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Saturday, August 13, 2016 9:16 AM

All replies

  • This behavior is 90% in the webpage you are using and maybe 10% the browser(s).

    Does the page you are logging into even support sharing cookies between the WebAPI calls and the Webpage?
    There are some good reasons to not share cookies (mostly tracking how a user is logged in). There might even be a different session ID for every client (inlcuding every browser). Especially instant messengers moved that that pattern heavily.

    Internet Explorer (what you give the cookie) and Mozilla have a seperate areas Temporary Internet files. Inlcuding seperate cookie storage and Certificate caches.

    Using a cookie to store the Session ID is customary. However, for cases where cookies are blocked a common workaround was to just append the Session ID to every link inside the application. Maybe you could just hand the Session ID in when you call the URL?


    Monday, August 8, 2016 6:56 PM
  • thanks  Christopher84 for replie,

    this site is java based . so i get JSESSIONID and insert it into webbrowser using SetInternetCookie. it is being set also. site diplay content  properly in webbrowser control. but it hits logout url automatically . i saw cookie in fiddler and cookie is being set properly.


    Monday, August 8, 2016 7:10 PM
  • Is there any one who can look into my issue.
     please help me on this i need to solve this on urgent basic.
    Tuesday, August 9, 2016 8:40 AM
  • Hi MrinalKumarJha,

    >>" i saw cookie in fiddler and cookie is being set properly."

    Please post your HTTP response message  after webclient request and HTTP request message from WebBrowser control for further discussion.

    I agree with @Christopher84, the issue is 90% caused by web server, because the rule is defined by web server.

    In addition, I suggest you use InternetSetCookieEx instead of InternetSetCookie. We could set the state of Cookie by dwFlags. For example, HTTPONLY or THIRD_PARTY.

    DWORD InternetSetCookieEx(
      _In_ LPCTSTR   lpszURL,
      _In_ LPCTSTR   lpszCookieName,
      _In_ LPCTSTR   lpszCookieData,
      _In_ DWORD     dwFlags,
      _In_ DWORD_PTR dwReserved
    );
    Best Regards,
    Li Wang

    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Saturday, August 13, 2016 9:16 AM