DotNetBrowser  1.14
Public Member Functions | List of all members
DotNetBrowser.CookieStorage Interface Reference

The system for storing and retrieving cookies. The cookies can be stored in the process memory (session cookies) or in files (persistent cookies). The CookieStorage provides access to both session and persistent cookies. More...

Public Member Functions

List< CookieGetAllCookies ()
 Returns all the cookies including secure and HTTP only cookies. This doesn't mark the cookies as having been accessed. More...
 
List< CookieGetAllCookies (string url)
 Returns all the cookies for given url including HTTP only cookies. More...
 
bool Delete (Cookie cookie)
 Deletes one specific cookie. The cookie instance can be received from a list of cookies returned from the GetAllCookies() method. More...
 
int DeleteAll ()
 Deletes all of the cookies including session, secure or HTTP only cookies. More...
 
bool SetCookie (string url, string name, string value, string domain, string path, long expirationTime, bool secure, bool httpOnly)
 Sets a cookie given explicit user-provided cookie attributes and associate it with the given url. More...
 
bool SetSessionCookie (string url, string name, string value, string domain, string path, bool secure, bool httpOnly)
 Sets a session cookie given explicit user-provided cookie attributes and associate it with the given url . More...
 
void Save ()
 Use this method to save all the changes you apply to this cookie storage. By default all the changes to the cookie store are made in memory, so when you restart the application you will not see the changes you made if you don't invoke this method on application exit. You can invoke this method after every change you made to cookie storage. More...
 

Detailed Description

The system for storing and retrieving cookies. The cookies can be stored in the process memory (session cookies) or in files (persistent cookies). The CookieStorage provides access to both session and persistent cookies.

The persistent cookies are stored in the Browser cache directory. By default all Browsers use predefined cache directory. You can find out where this directory is located using the BrowserPreferences.GetDefaultChromiumDir() method.

So, if Browser A and B have the same cache directory, then they will access the cookies of each other.

If you need to configure each Browser to use unique cookie storage which is not accessible for other Browser instances, you need to provide unique user data directory for each Browser instance. The user data directory path can be provided via configured BrowserContext.BrowserContext(string) object that must be passed into the BrowserFactory.Create(BrowserContext) factory method.

Member Function Documentation

bool DotNetBrowser.CookieStorage.Delete ( Cookie  cookie)

Deletes one specific cookie. The cookie instance can be received from a list of cookies returned from the GetAllCookies() method.

Parameters
cookiecookie to delete.
Returns
true when cookie was deleted successfully.
int DotNetBrowser.CookieStorage.DeleteAll ( )

Deletes all of the cookies including session, secure or HTTP only cookies.

Returns
the number of deleted cookies.
List<Cookie> DotNetBrowser.CookieStorage.GetAllCookies ( )

Returns all the cookies including secure and HTTP only cookies. This doesn't mark the cookies as having been accessed.

Returns
a list of all the cookies or empty list when there's no cookies.
List<Cookie> DotNetBrowser.CookieStorage.GetAllCookies ( string  url)

Returns all the cookies for given url including HTTP only cookies.

Parameters
urlthe URL associated with the returned cookies.
Returns
a list of all the cookies or empty list when there's no cookies.
void DotNetBrowser.CookieStorage.Save ( )

Use this method to save all the changes you apply to this cookie storage. By default all the changes to the cookie store are made in memory, so when you restart the application you will not see the changes you made if you don't invoke this method on application exit. You can invoke this method after every change you made to cookie storage.

bool DotNetBrowser.CookieStorage.SetCookie ( string  url,
string  name,
string  value,
string  domain,
string  path,
long  expirationTime,
bool  secure,
bool  httpOnly 
)

Sets a cookie given explicit user-provided cookie attributes and associate it with the given url.

This method expects each cookie attribute to be well-formed. It will check for disallowed characters (e.g. the ';' character is disallowed within the cookie value attribute) and will return false without setting the cookie if such characters are found.

If url and domain are different, the cookie will not be set and the method returns false. So, make sure that url and cookie domain are the same domains. For example, for http://www.teamdev.com address the cookie domain must be .teamdev.com

If you set the cookie successfully and the method returns true and you decide to find the cookie in the list of all cookies, please note that the cookie storage can modify some cookies attributes such as domain or expiration time.

Parameters
urla string that represents a valid URL which host will be associated with a new cookie instance. The url string must be valid and has the following format: http[https]://host. For example, http://www.google.com , https://www.gmail.com etc.
namethe cookie name.
valuethe cookie value.
domainthe cookie domain. For example, ".google.com".
paththe cookie path. For example, "/".
expirationTimethe expiration time in microseconds.
secureindicates whether cookie is secure.
httpOnlyindicates whether cookie is HTTPOnly.
Returns
when cookie was inserted successfully, otherwise - false. If the passed cookie is valid but already expired, the method returns true, but the cookie will not be in the list of all cookies.
bool DotNetBrowser.CookieStorage.SetSessionCookie ( string  url,
string  name,
string  value,
string  domain,
string  path,
bool  secure,
bool  httpOnly 
)

Sets a session cookie given explicit user-provided cookie attributes and associate it with the given url .

This method expects each cookie attribute to be well-formed. It will check for disallowed characters (e.g. the ';' character is disallowed within the cookie value attribute) and will return false without setting the cookie if such characters are found.

If url and domain are different, the cookie will not be set and the method returns false. So, make sure that url and cookie domain are the same domains. For example, for http://www.teamdev.com address the cookie domain must be .teamdev.com

If you set the cookie successfully and the method returns true and you decide to find the cookie in the list of all cookies, please note that the cookie storage can modify some cookies attributes such as domain or expiration time.

Parameters
urla string that represents a valid URL which host will be associated with a new cookie instance. The url string must be valid and has the following format: http[https]://host. For example, http://www.google.com, https://www.gmail.com etc.
namethe cookie name.
valuethe cookie value.
domainthe cookie domain. For example, ".google.com".
paththe cookie path. For example, "/".
secureindicates whether cookie is secure.
httpOnlyindicates whether cookie is HTTPOnly.
Returns
true when session cookie was inserted successfully, otherwise - false.