Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Been implementing the Basic security Authentication in a WCF Service.

Managed to get the .ASPXCookie from the web service. But, how to pass along the received cookie back to the next request?

var authClient = new MovieDbClient();
using (new OperationContextScope(authClient.InnerChannel))
{
    isValid = authClient.Login("userName", "passWord*");
    if (isValid)
    {
        var response = (HttpResponseMessageProperty)OperationContext.Current.IncomingMessageProperties[HttpResponseMessageProperty.Name];
        sharedCookie = response.Headers["Set-Cookie"];
    }
}

I tried to print the SharedCookie and was successful in it. It looks something like,

".ASPXAUTH=E499CA76EAC178A96BE5CA1E314CC90E0A6F9B95AD221EF5AD7D43598E701DC034D40904DBB8ECFBFB3EA21F2597D3C8DAB9B19A0491FD5858E9F0A4B6DC6E6A980FBB4CCADE191855A029CF8236C6890BEE28665C236992632807D1021AA138; expires=Tue, 07-Jan-2014 06:22:22 GMT; path=/; HttpOnly"

The question is how do I pass this cookie information in my next request using wCF Client - authClient ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
352 views
Welcome To Ask or Share your Answers For Others

1 Answer

To add a Cookie header to the WCF request in the current context given that you have the cookie string already:

var prop = new HttpRequestMessageProperty();
prop.Headers.Add(HttpRequestHeader.Cookie, sharedCookie);
OperationContext.Current.OutgoingMessageProperties.Add(HttpRequestMessageProperty.Name, prop);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...