开发者

How to clear a cookie programatically?

开发者 https://www.devze.com 2022-12-29 05:06 出处:网络
I am using silverlight unit tests to test an important part of our site. Is it possible to clear cookies before each unit test runs?

I am using silverlight unit tests to test an important part of our site. Is it possible to clear cookies before each unit test runs?

The problem is that if I do this,

HtmlPage.Document.Cookies = "";

It doesn't work. If the cookie already was this,

key = value

I can do this,

HtmlPage.Document.Cookies = "key=";

It kind of clears it out, but the string "key" is still part of the cookie.

Any ideas?

Are there any other classes in .NET that deal with cookies? The functionality seems quite limited when I am dealing with more complicate开发者_如何转开发d scenarios.


To delete existing cookie we actually just set its expiration time to some time in the past.

Jim McCurdy wrote a few classes that make the manipulation of cookies in Silverlight easier. See his Cookies for Silverlight post. There is a handly Delete method.

0

精彩评论

暂无评论...
验证码 换一张
取 消