Ejemplo n.º 1
0
        protected async Task SetCookieAsync(
            Controls.WinForms.WebView webView,
            string cookieName,
            string cookieValue,
            DateTime?expiry = null)
        {
            string formatExpiry(DateTime?e) => e != null
                ? $"; expires={e.Value.ToUniversalTime():R}"
                : string.Empty;

            var cookie = $"{cookieName}={cookieValue}{formatExpiry(expiry)}";

            if (webView != null)
            {
                await webView.InvokeScriptAsync("eval", $"document.cookie = \"{cookie}\"").ConfigureAwait(false);
            }
        }
Ejemplo n.º 2
0
 protected Task <string> GetCookiesAsync(Controls.WinForms.WebView webView)
 {
     return(webView.InvokeScriptAsync("eval", "document.cookie"));
 }