Setting Location header in response

416 views
Skip to first unread message

David Nichol

unread,
Mar 12, 2012, 1:43:31 PM3/12/12
to servic...@googlegroups.com
I'm new to ServiceStack, so perhaps I'm missing something...but how do I set headers in the response? It's nice that many of them are taken care of automatically, but if I want to allow a POST and set the Location header as part of the response (or a custom header, for that matter), how could that be done?

Thanks!

Dave

Demis Bellot

unread,
Mar 12, 2012, 1:44:36 PM3/12/12
to servic...@googlegroups.com

David Nichol

unread,
Mar 12, 2012, 3:13:41 PM3/12/12
to servic...@googlegroups.com
Right, I understand it's pretty easy to set global and per-service headers. Setting response headers in an OnPost method is what I'm looking for here. When my service receives a POST (per http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.2.2), I would like the 201 response to include the Location and ETag headers.

Thanks for the quick reply-

Dave


On Monday, March 12, 2012 1:44:36 PM UTC-4, mythz wrote:
This example shows how to set Global and per service HTTP headers:

Demis Bellot

unread,
Mar 12, 2012, 3:15:33 PM3/12/12
to servic...@googlegroups.com
So something like this then? :)

return new HttpResult(newMovie) {
StatusCode = HttpStatusCode.Created,
Headers = {
{ HttpHeaders.Location, this.RequestContext.AbsoluteUri.WithTrailingSlash() + newMovieId }
}
};

David Nichol

unread,
Mar 12, 2012, 4:17:27 PM3/12/12
to servic...@googlegroups.com
Seriously? Can't believe I missed that :)

Thanks!
Reply all
Reply to author
Forward
0 new messages