1

I want to write a simple win-forms tool for managing different social accounts.
I have a problem if user has several Facebook accounts. When I try to log in as second user I just got redirecting page in webBrowser.
I tried to use InternetSetOption and the INTERNET_SUPPRESS_COOKIE_PERSIST flag but it seems it does not help. How can I resolve this problem?

Login code

var lParameters = new Dictionary<string, object>();
lParameters["client_id"] = AppId;
lParameters["redirect_uri"] = "https://www.facebook.com/connect/login_success.html";
lParameters["response_type"] = "token";
lParameters["display"] = "popup";
lParameters["scope"] = "user_about_me";
Uri lUri = mFacebookClient.GetLoginUrl(lParameters);
Main.webBrowser.Navigate(lUri);

ADDED: Maybe I'm doing something wrong with InternetSetOption? Sorry for newbie question. I really should use it like in this answer How do I use InternetSetOption? It looks difficult...

Community
  • 1
  • 1
Yara_M
  • 633
  • 9
  • 29

1 Answers1

4

Most probable cause is because Facebook is setting a cookie with the session ID. INTERNET_SUPPRESS_COOKIE_PERSIST only makes cookies non-persistent, they will be cleared after the browser is destroyed or browser session finished, so if you are using the same instance they will still be alive.

You can finish your browsing session with InternetSetOption(0, 42, NULL, 0); (taken from here: http://social.msdn.microsoft.com/Forums/eu/csharpgeneral/thread/76a38eee-3ef6-4993-a54d-3fecc4eb6cff), so combining INTERNET_SUPPRESS_COOKIE_PERSIST and INTERNET_OPTION_END_BROWSER_SESSION (is what the 42 means) it should be cleared and ready for a new login.

Gusman
  • 14,905
  • 2
  • 34
  • 50
  • Thank you! But it works only if option "Remember me" turned off. Can I fix it? – Yara_M Apr 21 '14 at 23:59
  • If you use both options it should not allow any cookie to persist, so it should work... Set the cookie persist option before navigating and the end browser session option before changing accounts – Gusman Apr 22 '14 at 00:02