WSHttpBinding.AllowCookies Property
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Gets or sets a value that indicates whether the WCF client will automatically store and resend any cookies sent by a single web service.
public:
property bool AllowCookies { bool get(); void set(bool value); };
public bool AllowCookies { get; set; }
member this.AllowCookies : bool with get, set
Public Property AllowCookies As Boolean
Property Value
true
if automatic cookies processing is required; otherwise, false
.
Remarks
Setting AllowCookies to true
is useful when a client is interacting with one web service that uses cookies. If you are accessing multiple services with the same cookie, set AllowCookies to false
and you will have to manually add the cookie header to each outgoing message. The following code shows how to do this:
MyWebServiceClient client = new MyWebServiceClient();
using (new OperationContextScope(client.InnerChannel))
{
client.DoSomething();
// Extract the cookie embedded in the received web service response
// and stores it locally
HttpResponseMessageProperty response = (HttpResponseMessageProperty)
OperationContext.Current.IncomingMessageProperties[
HttpResponseMessageProperty.Name];
sharedCookie = response.Headers["Set-Cookie"];
}
MyOtherWebServiceClient otherClient = new MyOtherWebServiceClient();
using (new OperationContextScope(otherClient.InnerChannel))
{
// Embeds the extracted cookie in the next web service request
// Note that we manually have to create the request object since
// since it doesn't exist yet at this stage
HttpRequestMessageProperty request = new HttpRequestMessageProperty();
request.Headers["Cookie"] = sharedCookie;
OperationContext.Current.OutgoingMessageProperties[
HttpRequestMessageProperty.Name] = request;
otherClient.DoSomethingElse();
}
Applies to
.NET
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기