stefanprodan / WebApiThrottle

ASP.NET Web API rate limiter for IIS and Owin hosting

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to implement ThrottlingHandler.SetIdentity to be able to get ClientID from POST Body?

EkoGeek opened this issue · comments

I want to implement ThrottlingHandler.SetIdentity so that it fetches the ClientId from a application/x-www-form-urlencoded POST like:

POST /WebAPI.DemoThrottle/Values/Throttle HTTP/1.1
Host: localhost:63621
Content-Type: application/x-www-form-urlencoded

ClientId=MyClientId&OtherParam=123

I came up with the following:

protected override RequestIdentity SetIdentity(HttpRequestMessage request) { var form = request.Content.ReadAsFormDataAsync().Result; var clientId = form["ClientId"];

But this seems to remove the body from the Action in the controller:

public async Task<IHttpActionResult> Throttle([FromBody] ThrottleData throttle)

and throttle will be null.

Any suggestions or am I doing this the wrong way?