How to return HTTP 429?

时光总嘲笑我的痴心妄想 提交于 2019-11-30 04:41:13

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);

If you are hosting the WCF service with IIS you can turn on ASP.Net Compatibility Mode. With that done you can set the status of HttpContext.Current.Response.StatusCode to 429.

With that said. I think your best bet is to try casting the 429 to HttpStatusCode and seeing what happens. If that works then you can save yourself the headache.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!