How to return HTTP 429?
From the C# Language Specification 5.0:
The set of values that an enum type can take on is not limited by its enum members. In particular, any value of the underlying type of an enum can be cast to the enum type and is a distinct valid value of that enum type.
So this is completely alright to do and would be your best bet:
throw new WebFaultException((System.Net.HttpStatusCode)429);
In case somebody is using the webApi template, in which the controller is returning an IActionResult
object.
return new StatusCodeResult(429);
That worked for me.