silverlight 4, getting html cookies

2019-08-02 04:31发布

问题:

In Fiddler 2, Raw data shows the following cookies:

__utma_a2a=7477768302.1349257957.1317701031.1318843147.1318844585.14;   
 session="3YZAdX/xEuKVpYZWKBmcbC2S1YE=?
_flashes=KGxwMQooUydtZXNzYWdlJwpTJ0xvZ2dlZCBpbicKdHAyCmEoUydtZXNzYWdlJwpTJ0xvZ2dlZCBp
bicKdHAzCmEoUydtZXNzYWdlJwpTJ0xvZ2dlZCBpbicKdHA0CmEoUydtZXNzYWdlJwpTJ0xvZ2dlZCBpbicKd
HA1CmEoUydtZXNzYWdlJwpTJ0xvZ2dlZCBpbicKdHA2CmEoUydtZXNzYWdlJwpwNwpTJ0xvZ2dlZCBpbicKcD
gKdHA5CmEu&
_fresh=STAxCi4=&_id=UycwO0BAXHhlY1x4MTlceDA3LSBceGI1XHhlOVx4OWRceGQ3MFx4MTVceGIyJwpwMQou&
user_id=VjMKLg=="

(actually no space in between except after semicolon;)

But in Silverlight client

string[] cookies = System.Windows.Browser.HtmlPage.Document.Cookies.Split(';');

gets only 1 entry to the semicolon. All starting 'session' isn't in there. How can I get whole cookie string?

回答1:

Observe the HTTP conversation again in Fiddler and take not of the earlier response that contains the Set-Cookie header that sets the session cookie in the first place.

I suspect that cookie will have the "httpOnly" directive which means that it can not be retrieved by client code, it will be excluded by the standard APIs that expose cookies to script (or in this case Silverlight) code.