You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Cristi Pufu edited this page Feb 22, 2019
·
4 revisions
You can implement you own custom resolver contributors (for the client id and/or IP) via the RateLimitConfiguration class:
publicclassRateLimitConfiguration:IRateLimitConfiguration{protectedvirtualvoidRegisterResolvers(){if(!string.IsNullOrEmpty(ClientRateLimitOptions?.ClientIdHeader)){ClientResolvers.Add(newClientHeaderResolveContributor(HttpContextAccessor,ClientRateLimitOptions.ClientIdHeader));}// the contributors are resolved in the order of their collection indexif(!string.IsNullOrEmpty(IpRateLimitOptions?.RealIpHeader)){IpResolvers.Add(newIpHeaderResolveContributor(HttpContextAccessor,IpRateLimitOptions.RealIpHeader));}IpResolvers.Add(newIpConnectionResolveContributor(HttpContextAccessor));}}
There are some predefined resolve contributors:
IpConnectionResolveContributor - gets the IP from the HttpContext.Connection.RemoteIpAddress property
IpHeaderResolveContributor - gets the IP from the HTTP header named via the RealIpHeader application setting - can be used if the application is hosted behind a proxy
ClientHeaderResolveContributor - gets the Client Id from the HTTP header named via the ClientIdHeader application setting
You can define your own contributor by implementing the IClientResolveContributor interface (that for example parses the query string to get the Client Id) and add it to the configuration: