Exemple #1
0
        ContextMessageProperty OnReceiveHttpCookies(Message message)
        {
            ContextMessageProperty newContext = null;
            object property;

            if (message.Properties.TryGetValue(HttpResponseMessageProperty.Name, out property))
            {
                HttpResponseMessageProperty httpResponse = property as HttpResponseMessageProperty;
                if (httpResponse != null)
                {
                    string setCookieHeader = httpResponse.Headers[HttpResponseHeader.SetCookie];

                    if (!string.IsNullOrEmpty(setCookieHeader))
                    {
                        lock (this.cookieContainer)
                        {
                            if (!string.IsNullOrEmpty(setCookieHeader))
                            {
                                this.cookieContainer.SetCookies(this.Uri, setCookieHeader);
                                HttpCookieToolbox.TryCreateFromHttpCookieHeader(setCookieHeader, out newContext);
                            }

                            if (!this.contextManagementEnabled)
                            {
                                this.cookieContainer.SetCookies(this.Uri, HttpCookieToolbox.RemoveContextHttpCookieHeader);
                            }
                        }
                    }
                }
            }
            return(newContext);
        }
        void OnReceiveHttpCookies(Message message)
        {
            object property;

            if (message.Properties.TryGetValue(HttpRequestMessageProperty.Name, out property))
            {
                HttpRequestMessageProperty httpRequest = property as HttpRequestMessageProperty;
                if (httpRequest != null)
                {
                    string cookieHeader = httpRequest.Headers[HttpRequestHeader.Cookie];
                    ContextMessageProperty messageContext;
                    if (!string.IsNullOrEmpty(cookieHeader) && HttpCookieToolbox.TryCreateFromHttpCookieHeader(cookieHeader, out messageContext))
                    {
                        messageContext.AddOrReplaceInMessage(message);
                    }
                }
            }
        }