Soru

Zorluk: OrtaDefine API Management Policies

You are developing a solution that uses Azure API Management (APIM). You need to configure an inbound policy that forwards the client's original IP address to the backend service by adding a custom request header named `X-Client-IP`. You must use a C# policy expression within the `<set-header>` policy.

Complete the policy configuration by filling in the missing C# expression in the blank. What is the C# expression to retrieve the client's IP address from the request context?

Cevap:<inbound>
<base />
<set-header name="X-Client-IP" exists-action="override">
<value>@(【context.Request.IpAddress】)</value>
</set-header>
</inbound>

Cevap

context.Request.IpAddress
In Azure API Management, the context object is a read-only variable available within policy expressions. To access details about the client's request, you use the Request property of the context. The client's IP address is specifically exposed via the IpAddress property on the Request object. Therefore, the correct expression to fill the blank is context.Request.IpAddress.

Adım Adım Çözüm

1
Identify the context variable available in Azure API Management policy expressions.
The context variable is implicitly available in all APIM policy expressions.
Policy expressions are C# statements or expressions that have access to the context variable.
2
Determine the property of the context variable that represents the incoming HTTP request.
The context.Request property represents the incoming request sent by the client.
To retrieve information about the incoming client call (like headers, query parameters, or IP address), we must inspect the request context.
3
Locate the specific property containing the client's IP address on the Request object.
context.Request.IpAddress returns the IP address of the client as a string.
This property is populated by the API Management gateway with the caller's IP address.

Anahtar Kavram

Azure API Management context variables and policy expressions
Bu soruyu puanla