Logo
My Account |  Site Map | Contact Us  
Welcome Guest Search | Active Topics | Sign In | Register

CookieManager.GetCookies() do not return cookies url Options
AiSatan
Posted: Wednesday, April 3, 2019 10:07:50 AM
Rank: Advanced Member
Groups: Member

Joined: 2/11/2016
Posts: 35
Hi, I read that Engine.CookieManager.SetCookies() hang if you tried to set it without url, but I not found any place where I can get cookies' url, How I can get it for set the cookies later?
this method Engine.CookieManager.GetCookies() don't return urls
eo_support
Posted: Wednesday, April 3, 2019 11:01:49 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 21,360
What exactly are you trying to do?
AiSatan
Posted: Wednesday, April 3, 2019 11:04:01 AM
Rank: Advanced Member
Groups: Member

Joined: 2/11/2016
Posts: 35
I want to storage cookies in my properties and set them later (in the next run for example)
eo_support
Posted: Wednesday, April 3, 2019 11:09:42 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 21,360
Then you would just use SetCookies to add the cookie into the cookie storage. A cookie is always associated to a site (domain and Url). For example, a cookie associated to http://www.google.com would not be sent to http://www.yahoo.com. So when you call SetCookies, you MUST clearly specify the domain and the Url of the cookie. Usually you only set the domain and set the Url to the root of the site (set it to "/"). You can either set both directly on the Cookie object, or you can pass a url value when you call SetCookies. That way the Cookie's Domain and Url value will automatically derives from the url argument.
AiSatan
Posted: Wednesday, April 3, 2019 11:24:40 AM
Rank: Advanced Member
Groups: Member

Joined: 2/11/2016
Posts: 35
but https://www.essentialobjects.com/doc/eo.webengine.cookiemanager.setcookie.aspx ask for a url, that I don't have

I got all cookies by calling GetCookies and saved them, now I'm trying to Set them, but I don't not which url I should use, because if I call SetCookie("", cookie) it's just hang.

for example this code

Code: C#
private void Form1_Load(object sender, EventArgs e)
        {
            webView.Create(this.Handle);
            webView.LoadUrlAndWait("https://google.com"); // I loaded some url (for the example only I use google)
        }

        private void button1_Click(object sender, EventArgs e)
        {
            var allCookies = webView.Engine.CookieManager.GetCookies(); // I get all cookies
            webView.Engine.CookieManager.DeleteCookies();
            for (var i = 0; i < allCookies.Count; i++)
            {
                // now I want to set them,  but I have no field with url after calling getCookies
                webView.Engine.CookieManager.SetCookie(null, allCookies[i]); // I tried with null, "/" or "", one result is hang
            }
            allCookies = webView.Engine.CookieManager.GetCookies();
        }
eo_support
Posted: Wednesday, April 3, 2019 3:32:05 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 21,360
Hi,

You can create an Url based on the Cookie's Domain and Path. It will be something like this:

Code: C#
var cookie = allCookies[i];
string url = string.Format("{0}://www{1}{2}", cookie.Secure ? "https" : "http", cookie.Domain, cookie.Path);
webView.Engine.CookieManager.SetCookie(url, cookie);

Thanks!
AiSatan
Posted: Thursday, April 4, 2019 8:08:48 AM
Rank: Advanced Member
Groups: Member

Joined: 2/11/2016
Posts: 35
well, yes, I guess there's no other ways, thanks.
eo_support
Posted: Friday, April 12, 2019 9:56:00 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 21,360
Hi,

This is just to let you know that we have posted a new build that added an overloaded version of SetCookie that does not require the url argument:

https://www.essentialobjects.com/doc/eo.webengine.cookiemanager.setcookie_overload_2.aspx

You can download it from our download page. Please take a look and let us know how it goes.

Thanks!


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.