Jonathan Matheus
Jonathan Matheus

Reputation: 1350

Writing Cookies In Asp.net WebApi

I'm integrating with an sso system that requires setting a cookie during a POST operation. I don't see any way to do this using an HttpResponseMessage. I could take a dependency on HttpResponseBase in my controller, but that seems very ghetto. Any other way to do this?

Upvotes: 1

Views: 2457

Answers (2)

Alexander Zeitler
Alexander Zeitler

Reputation: 13089

You could return a Set-Cookie-Header using the Headers-Collection of the HttpResponseMessage.

Upvotes: 1

user423430
user423430

Reputation: 3704

Per this discussion, this is now a bit easier:

public HttpResponseMessage Post(int id, [FromBody]string value) {
 var result = this.Request.CreateResponse();
 result.Headers.AddCookies(new[] { new CookieHeaderValue("name", "value") });
 return result;
}

They keep changing this type of stuff though... (further reading)

Upvotes: 3

Related Questions