Skip to content

Instantly share code, notes, and snippets.

@DavidDeSloovere
Last active December 21, 2015 08:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DavidDeSloovere/6277610 to your computer and use it in GitHub Desktop.
Save DavidDeSloovere/6277610 to your computer and use it in GitHub Desktop.
System.Net.HttpResponseMessage set custom status code like 429
var response = new HttpResponseMessage
{
StatusCode = (HttpStatusCode)429,
ReasonPhrase = "Too Many Requests",
Content = new StringContent(string.Format(CultureInfo.InvariantCulture, "Rate limit reached. Reset in {0} seconds.", data.ResetSeconds))
};
response.Headers.Add("Retry-After", data.ResetSeconds.ToString(CultureInfo.InvariantCulture));
actionContext.Response = response;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment