Response.Headers["Set-Cookie"];获取的Cookie内容如何转成CookieCollection??

boyyao 2005-01-12 12:26:53
这个是相关的第4个提问了。一共有400分了。现在这个Cookie只能通过Response.Headers["Set-Cookie"];得到。但是Cookie提交的地方又是CookieCollectioon的。。两者如何互相转换的??
Response.Headers["Set-Cookie"];获得的内容如下:
SID=ARRGy4M1QVBtTU-ymi8bL6X8mVkctYbSbyDgdH8inu48rh_7FFxHE6MKYwqBFAJqlplUxq7hnBK5eqoh3E54jqk=;Domain=.google.com;Path=/,LSID=AaMBTixN1MqutGovVSOejyb8mVkctYbSbyDgdH8inu48rh_7FFxHE6MKYwqBFAJqlhCe_QqxLg00W5OZejb_UeQ=;Domain=www.google.com;Path=/accounts
...全文
3387 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
boyyao 2005-01-13
  • 打赏
  • 举报
回复
在MSDN中看见Cookie的重载列表如下。最多也就能保存Name Value Path Domain4个。但是我发现我登陆Gmail的时候Cookie除了这4个属性以外还有Expires属性。我应该怎么处理?另外Cookie除了这5个以外就没有其他属性了么?
非常感谢。。
重载列表
初始化 Cookie 类的新实例。

[Visual Basic] Public Sub New()
[C#] public Cookie();
[C++] public: Cookie();
[JScript] public function Cookie();
使用指定的 Name 和 Value 初始化 Cookie 类的新实例。

[Visual Basic] Public Sub New(String, String)
[C#] public Cookie(string, string);
[C++] public: Cookie(String*, String*);
[JScript] public function Cookie(String, String);
使用指定的 Name、Value 和 Path 初始化 Cookie 类的新实例。

[Visual Basic] Public Sub New(String, String, String)
[C#] public Cookie(string, string, string);
[C++] public: Cookie(String*, String*, String*);
[JScript] public function Cookie(String, String, String);
使用指定的 Name、Value、Path 和 Domain 初始化 Cookie 类的新实例。

[Visual Basic] Public Sub New(String, String, String, String)
[C#] public Cookie(string, string, string, string);
[C++] public: Cookie(String*, String*, String*, String*);
[JScript] public function Cookie(String, String, String, String);




Set-Cookie: GV=1010152ee8577-4a167ad39712d7e261ff281661974255; Domain=gmail.google.com; Path=/gmail
Set-Cookie: GMAIL_AT=3e765fc6b8c9c44-10152ee857a; Path=/
Set-Cookie: GMAIL_RTT=; Expires=Fri, 07-Jan-05 15:25:58 GMT; Path=/
Set-Cookie: GMAIL_RTT2=; Domain=google.com; Expires=Fri, 07-Jan-05 15:25:58 GMT; Path=/
Set-Cookie: GMAIL_STAT=; Expires=Fri, 07-Jan-05 15:25:58 GMT; Path=/
Set-Cookie: GMAIL_LOGIN=; Expires=Fri, 07-Jan-05 15:25:58 GMT; Path=/
Set-Cookie: GMAIL_LOGIN2=; Domain=google.com; Expires=Fri, 07-Jan-05 15:25:58 GMT; Path=/
saucer 2005-01-13
  • 打赏
  • 举报
回复
Expires is used to set the expiry date for the cookie, you can set it to anything in the future to keep your cookie alive or anything in the past to make it expire
saucer 2005-01-12
  • 打赏
  • 举报
回复
it depends on your application

CookieCollection cc =new CookieCollection();
string s = "SID=ARRGy4M1QVBtTU-ymi8bL6X8mVkctYbSbyDgdH8inu48rh_7FFxHE6MKYwqBFAJqlplUxq7hnBK5eqoh3E54jqk=;Domain=.google.com;Path=/,LSID=AaMBTixN1MqutGovVSOejyb8mVkctYbSbyDgdH8inu48rh_7FFxHE6MKYwqBFAJqlhCe_QqxLg00W5OZejb_UeQ=;Domain=www.google.com;Path=/accounts";
Regex re = new Regex("([^;,]+)=([^;,]+);Domain=([^;,]+);Path=([^;,]+)", RegexOptions.IgnoreCase);
foreach (Match m in re.Matches(s))
{
//name, value, path, domain
Cookie c = new Cookie(m.Groups[1].Value, m.Groups[2].Value,m.Groups[3].Value,m.Groups[3].Value);
cc.Add(c);
}
boyyao 2005-01-12
  • 打赏
  • 举报
回复
CookieCollection是一个集合把?除了Name和Value以外Domain和Path需要么?
saucer 2005-01-12
  • 打赏
  • 举报
回复
you have to parse the string programmatically and create Cookie objects and add them to the CookieCollection, use String's Split method or regular expresssions, for example

110,566

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧