Skip to content
This repository has been archived by the owner on Nov 1, 2023. It is now read-only.

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

Open
EkoGeek opened this issue Dec 17, 2018 · 0 comments

Comments

@EkoGeek
Copy link

EkoGeek commented Dec 17, 2018

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?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant