问题
An example of what I am looking for is as follows but the allow-access element does not exist. What can I replace with so that the subscription key is not checked. i.e. in this case it would allow all callers access to the controller as long as they are making GET requests.
<policies>
<inbound>
<base />
<choose>
<when condition="@(context.Request.Method.Equals("GET"))">
<allow-access />
</when>
</choose>
</inbound>
<backend>
<base />
</backend>
<outbound>
<base />
</outbound>
<on-error>
<base />
</on-error>
Any help would be appreciated.
回答1:
A workaround would be to turn off the Requires subscription
setting on the product and check the subscription key in the inbound policy by yourself. Here is an example of how to do it.
- Go to Settings of Starter product.
- Uncheck Requires subscription and save.
- Open the policies of the product and add the following policy to the inbound. The value of
<check-header>
policy is the subscription key of the Starter product.
<choose>
<when condition="@(!context.Request.Method.Equals("GET"))">
<check-header name="Ocp-Apim-Subscription-Key" failed-check-httpcode="401" failed-check-error-message="Not authorized" ignore-case="false">
<value>920b4e307f4f41ff9bd4a3bd6a5450ee</value>
</check-header>
</when>
</choose>
来源:https://stackoverflow.com/questions/62900564/is-it-possible-to-create-a-policy-that-will-conditionally-expose-an-api-manageme