asp.net - WebBrowser control in web server not returning Cookie from Website -


i attempting go https site webbrowser control in web application, basic information site (the site not have web service or other api @ point) when iis express able connect login , navigate other pages when directly connecting web browser on system works fine.

from development systems i.e. windows 10 or windows server 2016 can publish web application, connect web application , through web application connect site, login , load other pages works fine. but…. when deploy godaddy , connect site through application able log in when navigate page redirected login page.

i have noticed not jsession cookies when going through application on godaddy them in of other successful cases. receive jsesson cookies before log in @ target site: http://www.altavista.com/ website returns cookies on connect should suffice. have changed user agent same agent have on desktop , connected , still same results on godaddy.

i have tried on godaddy sites ssl protected (https) , not (http). has run type of problem before using webbrowser control?

here’s test snippet of code (as might note have tried lots of things figure out cookiepresistance, clearing cookies, jscript clear status etc.:

public static class nativemethods {     [dllimport("wininet.dll", setlasterror = true)]     private static extern bool internetsetoption(intptr hinternet, int dwoption,                                                  intptr lpbuffer, int lpdwbufferlength);      public static void suppresscookiepersist()     {         int dwoption = 81; //internet_option_suppress_behavior         int option = 3; // internet_suppress_cookie_persist          intptr optionptr = marshal.allochglobal(sizeof(int));         marshal.writeint32(optionptr, option);          bool x = internetsetoption(intptr.zero, dwoption, optionptr, sizeof(int));         marshal.freehglobal(optionptr);     }     public static void enablecookiepersist()     {         int dwoption = 81; //internet_option_suppress_behavior         int option = 4; // internet_suppress_cookie_policy ignores policy , allows cookies set https://msdn.microsoft.com/en-us/library/windows/desktop/aa385328(v=vs.85).aspx          intptr optionptr = marshal.allochglobal(sizeof(int));         marshal.writeint32(optionptr, option);          internetsetoption(intptr.zero, dwoption, optionptr, sizeof(int));         option = 1;         marshal.writeint32(optionptr, option);         internetsetoption(intptr.zero, dwoption, optionptr, sizeof(int));         marshal.freehglobal(optionptr);     }     public static void clearbrowsersession()     {         int dwoption = 42; //internet_option_end_browser_session          internetsetoption(intptr.zero, dwoption, intptr.zero, 0);      } }     public partial class teststub: system.web.ui.page {     protected void btnnavigate_click(object sender, eventargs e)     {         nativemethods.enablecookiepersist();         if(tburl.text == "")         {             client_alert("please enter url");             return;         }         if (tbuseragent.text == "")             tbuseragent.text = currentuseragent;         object o = tburl.text;          var t = new thread((parameterizedthreadstart)getpage);         t.setapartmentstate(apartmentstate.sta);         t.start(o);          gettingpage = true;         while (gettingpage == true)             thread.sleep(500);         t.join();         return;     }      private void getpage(object o)     {          stringbuilder sb = new stringbuilder();         directorbrowser = new webbrowser();          nativemethods.clearbrowsersession();         directorbrowser.scrollbarsenabled = false;         directorbrowser.scripterrorssuppressed = true;         directorbrowser.allownavigation = true;         directorbrowser.navigate("javascript:void((function(){var a,b,c,e,f;f=0;a=document.cookie.split('; '); (e = 0; e < a.length && a[e]; e++) { f++; (b = '.' + location.host; b; b = b.replace(/^ (?:% 5c.|[^% 5c.] +) /, '')){ (c = location.pathname; c; c = c.replace(/.$/, '')) { document.cookie = (a[e] + '; domain=' + b + '; path=' + c + '; expires=' + new date((new date()).gettime() - 1e11).togmtstring()); } }}})())");         nativemethods.enablecookiepersist();          directorbrowser.documentcompleted += new webbrowserdocumentcompletedeventhandler(browser_noticecompleted);         uri url = new uri((string)o);         directorbrowser.navigate(url, null, null, "user-agent: " + tbuseragent.text);          gettingpage = true;          while (gettingpage == true)         {             system.windows.forms.application.doevents();             thread.sleep(500);         }     }     private void browser_noticecompleted(object sender, webbrowserdocumentcompletedeventargs e)     {         if (gettingpage == true)         {             htmlelement body = directorbrowser.document.body;             htmlelementcollection inputs = directorbrowser.document.getelementsbytagname("input");             htmlelementcollection forms = directorbrowser.document.forms;             body = directorbrowser.document.body;             string webresults = body.innerhtml;             htmlagilitypack.htmldocument htmldoc = new htmlagilitypack.htmldocument();             htmldoc.loadhtml(webresults);             htmldoc.optionfixnestedtags = true;              tbmaintenanceresults.text = "cookies: <br>" + directorbrowser.document.cookie + "<br>" + body.innerhtml;             gettingpage = false;         }         else         {             gettingpage = false;         }     } } 

after adding custom security manager, , still not having success:

public partial  class internetsecuritymanager : iinternetsecuritymanager {     private static guid _clsid_securitymanager = new guid("7b8a2d94-0ac9-11d1-896c-00c04fb6bfc4");     private static string[] zonenames = new[] { "local", "intranet", "trusted", "internet", "restricted" };public static string geturlzone(string url)     {          type t = system.type.gettypefromclsid(_clsid_securitymanager);         iinternetsecuritymanager securitymanager = (iinternetsecuritymanager)system.activator.createinstance(t);         try         {             uint zone = 0;             int hresult = securitymanager.mapurltozone(url, ref zone, 0);             if (hresult != 0)                 throw new comexception("error calling mapurltozone, hresult = " + hresult.tostring("x"), hresult);              if (zone < zonenames.length)                 return zonenames[zone];             return "unknown - " + zone;         }                 {             marshal.releasecomobject(securitymanager);         }     }     public static void geturlzonecookiespermissions(string url)     {         type t = system.type.gettypefromclsid(_clsid_securitymanager);         iinternetsecuritymanager securitymanager = (iinternetsecuritymanager)system.activator.createinstance(t);         try         {              uint puaf = 0x00000040;  //puaf trusted             byte obptr = 0;             int hresult = securitymanager.processurlaction(url, 0x00001a06, out obptr, 1, 0, 0, puaf, 0);             //hresult = securitymanager.processurlaction(url, 0x00001a10, out obptr, 1, 0, 0, puaf, 0);             hresult = securitymanager.processurlaction(url, 0x00001a03, out obptr, 1, 0, 0, puaf, 0);             return;         }                 {             marshal.releasecomobject(securitymanager);         }     }      [return: marshalas(unmanagedtype.i4)]     public int setsecuritysite([in] intptr psite)     {         return convert.toint32( 0x800c0011); //inet_e_default_action;     }      [return: marshalas(unmanagedtype.i4)]     public int getsecuritysite([out] intptr psite)     {         return convert.toint32(0x800c0011); //inet_e_default_action;     }      [return: marshalas(unmanagedtype.i4)]     public int mapurltozone([in, marshalas(unmanagedtype.lpwstr)] string pwszurl, ref uint pdwzone, uint dwflags)     {         return convert.toint32(0x800c0011); //inet_e_default_action;     }      [return: marshalas(unmanagedtype.i4)]     public int getsecurityid([marshalas(unmanagedtype.lpwstr)] string pwszurl, [marshalas(unmanagedtype.lparray)] byte[] pbsecurityid, ref uint pcbsecurityid, uint dwreserved)     {         return convert.toint32(0x800c0011); //inet_e_default_action;     }      [return: marshalas(unmanagedtype.i4)]     public int processurlaction([in, marshalas(unmanagedtype.lpwstr)] string pwszurl, uint dwaction, out byte ppolicy, uint cbpolicy, byte pcontext, uint cbcontext, uint dwflags, uint dwreserved)     {                  ppolicy = 0;                 return 0;// s_ok;     }      [return: marshalas(unmanagedtype.i4)]     public int querycustompolicy([in, marshalas(unmanagedtype.lpwstr)] string pwszurl, ref guid guidkey, ref byte pppolicy, ref uint pcbpolicy, ref byte pcontext, uint cbcontext, uint dwreserved)     {         return convert.toint32(0x800c0011); //inet_e_default_action;     }      [return: marshalas(unmanagedtype.i4)]     public int setzonemapping(uint dwzone, [in, marshalas(unmanagedtype.lpwstr)] string lpszpattern, uint dwflags)     {         return convert.toint32(0x800c0011); //inet_e_default_action;     }      [return: marshalas(unmanagedtype.i4)]     public int getzonemappings(uint dwzone, out ucomienumstring ppenumstring, uint dwflags)     {         ppenumstring = null;         return convert.toint32(0x800c0011); //inet_e_default_action;     }   }  [comimport, guidattribute("79eac9ee-baf9-11ce-8c82-00aa004ba90b")] [interfacetypeattribute(cominterfacetype.interfaceisiunknown)] public interface iinternetsecuritymanager {     [return: marshalas(unmanagedtype.i4)]     [preservesig]     int setsecuritysite([in] intptr psite);      [return: marshalas(unmanagedtype.i4)]     [preservesig]     int getsecuritysite([out] intptr psite);      [return: marshalas(unmanagedtype.i4)]     [preservesig]     int mapurltozone([in, marshalas(unmanagedtype.lpwstr)] string pwszurl,              ref uint32 pdwzone, uint32 dwflags);      [return: marshalas(unmanagedtype.i4)]     [preservesig]     int getsecurityid([marshalas(unmanagedtype.lpwstr)] string pwszurl,               [marshalas(unmanagedtype.lparray)] byte[] pbsecurityid,               ref uint32 pcbsecurityid, uint dwreserved);      [return: marshalas(unmanagedtype.i4)]     [preservesig]     int processurlaction([in, marshalas(unmanagedtype.lpwstr)] string pwszurl,              uint32 dwaction, out byte ppolicy, uint32 cbpolicy,              byte pcontext, uint32 cbcontext, uint32 dwflags,              uint32 dwreserved);      [return: marshalas(unmanagedtype.i4)]     [preservesig]     int querycustompolicy([in, marshalas(unmanagedtype.lpwstr)] string pwszurl,               ref guid guidkey, ref byte pppolicy, ref uint32 pcbpolicy,               ref byte pcontext, uint32 cbcontext, uint32 dwreserved);      [return: marshalas(unmanagedtype.i4)]     [preservesig]     int setzonemapping(uint32 dwzone,                [in, marshalas(unmanagedtype.lpwstr)] string lpszpattern,                uint32 dwflags);      [return: marshalas(unmanagedtype.i4)]     [preservesig]     int getzonemappings(uint32 dwzone, out ucomienumstring ppenumstring,             uint32 dwflags);       } } 

i found post 2006: http://www.tech-archive.net/archive/inetsdk/microsoft.public.inetsdk.programming.webbrowser_ctl/2006-03/msg00073.html apparently cookies not handled security manager handled zone manager cannot customized. way fix add additional zone specific needs registry. unfortunately there no way code when using webbrowser control. , if site hosted in web farm don't have access registry approach needed (possibly ie plug in or deploy on server have access , permission set default browser need)


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -