在WPF Web浏览器控件中删除Cookie [英] Deleting cookies in WPF web browser control

查看:89
本文介绍了在WPF Web浏览器控件中删除Cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个与Twitter API一起使用的WPF应用程序。为了显示Twitter身份验证页面,我正在使用WPF Web浏览器控件。我能够成功登录和使用Twitter API。我的问题是我需要清除网络浏览器的Cookie才能实现注销功能。有什么方法可以在WPF Web浏览器中清除会话cookie?

I am developing a WPF application in which I am working with twitter API. To show twitter authentication page I am using WPF web-browser control. I am able to login and use twitter API successfully. My problem is that I need to clear web browser's cookies to implement logout functionality. Is there any way to clear session cookies in WPF web browser?

推荐答案

检查以下内容,

http: //social.msdn.microsoft.com/Forums/zh-CN/wpf/thread/860d1b66-23c2-4a64-875b-1cac869a5e5d

private static void _DeleteSingleCookie(string name, Uri url)
    {
        try
        {
            // Calculate "one day ago"
            DateTime expiration = DateTime.UtcNow - TimeSpan.FromDays(1);
            // Format the cookie as seen on FB.com.  Path and domain name are important factors here.
            string cookie = String.Format("{0}=; expires={1}; path=/; domain=.facebook.com", name, expiration.ToString("R"));
            // Set a single value from this cookie (doesnt work if you try to do all at once, for some reason)
            Application.SetCookie(url, cookie);
        }
        catch (Exception exc)
        {
            Assert.Fail(exc + " seen deleting a cookie.  If this is reasonable, add it to the list.");
        }
    }

这篇关于在WPF Web浏览器控件中删除Cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆