Skip to content

Commit 6433a05

Browse files
Merge pull request #311316 from MicrosoftDocs/main
Auto Publish – main to live - 2026-02-04 06:00 UTC
2 parents 1017452 + 9f07f9f commit 6433a05

31 files changed

Lines changed: 1062 additions & 479 deletions

articles/api-management/api-management-policy-expressions.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ author: dlepow
77
ms.service: azure-api-management
88
ms.custom: devx-track-dotnet
99
ms.topic: reference
10-
ms.date: 03/07/2023
10+
ms.date: 01/15/2026
1111
ms.author: danlep
1212
---
1313
# API Management policy expressions
@@ -202,16 +202,18 @@ The `context` variable is implicitly available in every policy [expression](api-
202202

203203
|Context Variable|Allowed methods, properties, and parameter values|
204204
|----------------------|-------------------------------------------------------|
205-
|`context`|[`Api`](#ref-context-api): [`IApi`](#ref-iapi)<br /><br /> [`Deployment`](#ref-context-deployment)<br /><br /> Elapsed: `TimeSpan` - time interval between the value of `Timestamp` and current time<br /><br /> [`GraphQL`](#ref-context-graphql)<br /><br />[`LastError`](#ref-context-lasterror)<br /><br /> [`Operation`](#ref-context-operation)<br /><br /> [`Request`](#ref-context-request)<br /><br /> `RequestId`: `Guid` - unique request identifier<br /><br /> [`Response`](#ref-context-response)<br /><br /> [`Subscription`](#ref-context-subscription)<br /><br />`Timestamp`: `DateTime` - point in time when request was received<br /><br /> `Tracing`: `bool` - indicates if tracing is on or off <br /><br /> [User](#ref-context-user)<br /><br /> [`Variables`](#ref-context-variables): `IReadOnlyDictionary<string, object>`<br /><br /> `void Trace(message: string)` <br /><br /> [`Workspace`](#ref-context-workspace) |
205+
|`context`|[`Api`](#ref-context-api): [`IApi`](#ref-iapi)<br /><br /> [`Backend`](#ref-context-backend)<br /><br /> [`Deployment`](#ref-context-deployment)<br /><br /> Elapsed: `TimeSpan` - time interval between the value of `Timestamp` and current time<br /><br /> [`GraphQL`](#ref-context-graphql)<br /><br />[`LastError`](#ref-context-lasterror)<br /><br /> [`Operation`](#ref-context-operation)<br /><br /> [`Request`](#ref-context-request)<br /><br /> `RequestId`: `Guid` - unique request identifier<br /><br /> [`Response`](#ref-context-response)<br /><br /> [`Subscription`](#ref-context-subscription)<br /><br />`Timestamp`: `DateTime` - point in time when request was received<br /><br /> `Tracing`: `bool` - indicates if tracing is on or off <br /><br /> [User](#ref-context-user)<br /><br /> [`Variables`](#ref-context-variables): `IReadOnlyDictionary<string, object>`<br /><br /> `void Trace(message: string)` <br /><br /> [`Workspace`](#ref-context-workspace) |
206206
|<a id="ref-context-api"></a>`context.Api`|`Id`: `string`<br /><br /> `IsCurrentRevision`: `bool`<br /><br /> `Name`: `string`<br /><br /> `Path`: `string`<br /><br /> `Revision`: `string`<br /><br /> `ServiceUrl`: [`IUrl`](#ref-iurl)<br /><br /> `Version`: `string` |
207+
|<a id="ref-context-backend"></a>`context.Backend`|`AzureRegion`: `string`<br /><br /> `Id`: `string`<br /><br /> `Type`: `enum BackendType {Single, Pool}`|
207208
|<a id="ref-context-deployment"></a>`context.Deployment`|[`Gateway`](#ref-context-gateway)<br /><br /> `GatewayId`: `string` (returns 'managed' for managed gateways)<br /><br /> `Region`: `string`<br /><br /> `ServiceId`: `string`<br /><br /> `ServiceName`: `string`<br /><br />[`SustainabilityInfo`](#ref-context-sustainability)<br/><br/> `Certificates`: `IReadOnlyDictionary<string, X509Certificate2>`|
208209
|<a id="ref-context-gateway"></a>`context.Deployment.Gateway`|`Id`: `string` (returns 'managed' for managed gateways)<br /><br /> `InstanceId`: `string` (returns 'managed' for managed gateways)<br /><br /> `IsManaged`: `bool`|
209210
|<a id="ref-context-sustainability"></a>`context.Deployment.SustainabilityInfo`| `CurrentCarbonIntensity`: Enum [CarbonIntensityCategory](sustainability.md#carbon-intensity-categories)|
210211
|<a id="ref-context-graphql"></a>`context.GraphQL`|`GraphQLArguments`: `IGraphQLDataObject`<br /><br /> `Parent`: `IGraphQLDataObject`<br/><br/>[Examples](configure-graphql-resolver.md#graphql-context)|
211212
|<a id="ref-context-lasterror"></a>`context.LastError`|`Source`: `string`<br /><br /> `Reason`: `string`<br /><br /> `Message`: `string`<br /><br /> `Scope`: `string`<br /><br /> `Section`: `string`<br /><br /> `Path`: `string`<br /><br /> `PolicyId`: `string`<br /><br /> For more information about `context.LastError`, see [Error handling](api-management-error-handling-policies.md).|
212213
|<a id="ref-context-operation"></a>`context.Operation`|`Id`: `string`<br /><br /> `Method`: `string`<br /><br /> `Name`: `string`<br /><br /> `UrlTemplate`: `string`|
213214
|<a id="ref-context-product"></a>`context.Product`|`ApprovalRequired`: `bool`<br /><br /> `Groups`: `IEnumerable<`[`IGroup`](#ref-igroup)`>`<br /><br /> `Id`: `string`<br /><br /> `Name`: `string`<br /><br /> `State`: `enum ProductState {NotPublished, Published}`<br /><br /> `SubscriptionsLimit`: `int?`<br /><br /> `SubscriptionRequired`: `bool`|
214-
|<a id="ref-context-request"></a>`context.Request`|`Body`: [`IMessageBody`](#ref-imessagebody) or `null` if request doesn't have a body.<br /><br /> `Certificate`: `System.Security.Cryptography.X509Certificates.X509Certificate2`<br /><br /> [`Headers`](#ref-context-request-headers): `IReadOnlyDictionary<string, string[]>`<br /><br /> `IpAddress`: `string`<br /><br /> `MatchedParameters`: `IReadOnlyDictionary<string, string>`<br /><br /> `Method`: `string`<br /><br /> `OriginalUrl`: [`IUrl`](#ref-iurl)<br /><br /> `Url`: [`IUrl`](#ref-iurl)<br /><br /> `PrivateEndpointConnection`: [`IPrivateEndpointConnection`](#ref-iprivateendpointconnection) or `null` if request doesn't come from a private endpoint connection.|
215+
|<a id="ref-context-request"></a>`context.Request`|`Body`: [`IMessageBody`](#ref-imessagebody) or `null` if request doesn't have a body.<br /><br /> `Certificate`: `System.Security.Cryptography.X509Certificates.X509Certificate2`<br /><br /> [`Foundry`](#ref-context-request-foundry)<br /><br /> [`Headers`](#ref-context-request-headers): `IReadOnlyDictionary<string, string[]>`<br /><br /> `IpAddress`: `string`<br /><br /> `MatchedParameters`: `IReadOnlyDictionary<string, string>`<br /><br /> `Method`: `string`<br /><br /> `OriginalUrl`: [`IUrl`](#ref-iurl)<br /><br /> `Url`: [`IUrl`](#ref-iurl)<br /><br /> `PrivateEndpointConnection`: [`IPrivateEndpointConnection`](#ref-iprivateendpointconnection) or `null` if request doesn't come from a private endpoint connection.|
216+
|<a id="ref-context-request-foundry"></a>`context.Request.Foundry`|`Deployment`: `string` - The model deployment ID in Microsoft Foundry associated with the request.|
215217
|<a id="ref-context-request-headers"></a>`string context.Request.Headers.GetValueOrDefault(headerName: string, defaultValue: string)`|`headerName`: `string`<br /><br /> `defaultValue`: `string`<br /><br /> Returns comma-separated request header values or `defaultValue` if the header isn't found.|
216218
|<a id="ref-context-response"></a>`context.Response`|`Body`: [`IMessageBody`](#ref-imessagebody)<br /><br /> [`Headers`](#ref-context-response-headers): `IReadOnlyDictionary<string, string[]>`<br /><br /> `StatusCode`: `int`<br /><br /> `StatusReason`: `string`|
217219
|<a id="ref-context-response-headers"></a>`string context.Response.Headers.GetValueOrDefault(headerName: string, defaultValue: string)`|`headerName`: `string`<br /><br /> `defaultValue`: `string`<br /><br /> Returns comma-separated response header values or `defaultValue` if the header isn't found.|

articles/api-management/backends.md

Lines changed: 44 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
---
2-
title: Azure API Management backends | Microsoft Docs
2+
title: Azure API Management Backends | Microsoft Docs
33
description: Learn about backends in Azure API Management. Backend entities encapsulate information about backend services, promoting reusability across APIs and governance.
44
services: api-management
55
author: dlepow
66
ms.service: azure-api-management
77
ms.topic: concept-article
8-
ms.date: 11/20/2025
8+
ms.date: 01/15/2026
99
ms.author: danlep
1010
ms.custom:
1111
- build-2024
@@ -23,28 +23,28 @@ When you import certain APIs, API Management automatically configures the API ba
2323
* A [SOAP API](import-soap-api.md).
2424

2525
For other APIs, such as APIs from Azure services, you import an Azure resource without specifying the backend service explicitly. Examples include:
26-
* An HTTP-triggered [Azure Function App](import-function-app-as-api.md)
26+
* An HTTP-triggered [Azure Function App](import-function-app-as-api.md).
2727
* A [Logic App](import-logic-app-as-api.md).
2828

2929
API Management also supports using other resources as an API backend, such as:
3030
* A [Service Fabric cluster](how-to-configure-service-fabric-backend.yml).
31-
* AI services
32-
* A custom service
31+
* AI services.
32+
* A custom service.
3333

3434
For these backends, you can create a *backend entity* in API Management and reference it in your APIs.
3535

3636
## Benefits of backends
3737

38-
API Management supports backend entities so you can manage the backend services of your API. A backend entity encapsulates information about the backend service, promoting reusability across APIs and improved governance.
38+
API Management supports backend entities so you can manage the backend services of your API. A backend entity encapsulates information about the backend service, which promotes reusability across APIs and improves governance.
3939

40-
Use backends for one or more of the following:
40+
Use backends for one or more of the following tasks:
4141

42-
* Authorize the credentials of requests to the backend service
43-
* Take advantage of API Management functionality to maintain secrets in Azure Key Vault if [named values](api-management-howto-properties.md) are configured for header or query parameter authentication
44-
* Define circuit breaker rules to protect your backend from too many requests
45-
* Route or load-balance requests to multiple backends
42+
* Authorize the credentials of requests to the backend service.
43+
* Take advantage of API Management functionality to maintain secrets in Azure Key Vault if [named values](api-management-howto-properties.md) are configured for header or query parameter authentication.
44+
* Define circuit breaker rules to protect your backend from too many requests.
45+
* Route or load-balance requests to multiple backends.
4646

47-
Configure and manage backend entities in the Azure portal, or by using Azure APIs or tools.
47+
You can configure and manage backend entities in the Azure portal, or by using Azure APIs or tools.
4848

4949
## Create a backend
5050

@@ -98,7 +98,7 @@ If the backend service is secured with a certificate issued by a well-known CA,
9898

9999
### Configure CA certificate
100100

101-
If the backend service uses a custom CA certificate, you can reference the custom CA certificate in the backend entity. You might need to do this step to establish trust for the backend server certificate - for example, with self-signed certificates, untrusted root certificates, or partial certificate chains.
101+
If the backend service uses a custom CA certificate, you can reference the custom CA certificate in the backend entity. You might need to add a custom CA certificate to establish trust for the backend server certificate - for example, with self-signed certificates, untrusted root certificates, or partial certificate chains.
102102

103103
> [!NOTE]
104104
> Currently, you can only configure CA certificate details in a backend entity in the [v2 tiers](v2-service-tiers-overview.md).
@@ -123,7 +123,7 @@ To add CA certificate details, follow these steps:
123123
124124
## Reference backend using set-backend-service policy
125125

126-
After creating a backend, you can reference the backend identifier (name) in your APIs. Use the [`set-backend-service`](set-backend-service-policy.md) policy to direct an incoming API request to the backend. If you already configured a backend web service for an API, you can use the `set-backend-service` policy to redirect the request to a backend entity instead. For example:
126+
After creating a backend, reference the backend identifier (name) in your APIs. Use the [`set-backend-service`](set-backend-service-policy.md) policy to direct an incoming API request to the backend. If you already configured a backend web service for an API, use the `set-backend-service` policy to redirect the request to a backend entity instead. For example:
127127

128128
```xml
129129
<policies>
@@ -135,11 +135,11 @@ After creating a backend, you can reference the backend identifier (name) in you
135135
<policies/>
136136
```
137137
> [!NOTE]
138-
> Alternatively, you can use `base-url`. Usually, the format is `https://backend.com/api`. Avoid adding a slash at the end to prevent misconfigurations. Typically, the `base-url` and HTTP(S) endpoint value in the backend should match to enable seamless integration between frontend and backend. Note that API Management instances append the backend service name to the `base-url`.
138+
> Alternatively, you can use `base-url`. Usually, the format is `https://backend.com/api`. Avoid adding a slash at the end to prevent misconfigurations. Typically, the `base-url` and HTTP(S) endpoint value in the backend should match to enable seamless integration between frontend and backend. API Management instances append the backend service name to the `base-url`.
139139
140-
You can use conditional logic with the `set-backend-service` policy to change the effective backend based on location, gateway that was called, or other expressions.
140+
Use conditional logic with the `set-backend-service` policy to change the effective backend based on location, gateway that was called, or other expressions.
141141

142-
For example, here is a policy to route traffic to another backend based on the gateway that was called:
142+
For example, the following policy routes traffic to another backend based on the gateway that was called:
143143

144144
```xml
145145
<policies>
@@ -275,7 +275,7 @@ Include a JSON snippet similar to the following in your ARM template for a backe
275275

276276
## Load-balanced pool
277277

278-
API Management supports backend *pools* when you want to implement multiple backends for an API and load-balance requests across those backends. A pool is a collection of backends that are treated as a single entity for load balancing.
278+
API Management supports backend *pools* when you want to implement multiple backends for an API and load-balance requests across those backends. A pool is a collection of backends that the service treats as a single entity for load balancing.
279279

280280
Use a backend pool for scenarios such as the following scenarios:
281281

@@ -303,7 +303,7 @@ API Management supports the following load balancing options for backend pools:
303303
304304
### Session awareness
305305

306-
With any of the preceding load balancing options, you can enable **session awareness** (session affinity) to ensure that all requests from a specific user during a session go to the same backend in the pool. API Management sets a session ID cookie to maintain session state. This option is useful, for example, in scenarios with backends such as AI chat assistants or other conversational agents to route requests from the same session to the same endpoint.
306+
By using any of the preceding load balancing options, you can enable **session awareness** (session affinity) to ensure that all requests from a specific user during a session go to the same backend in the pool. API Management sets a session ID cookie to maintain session state. This option is useful, for example, in scenarios with backends such as AI chat assistants or other conversational agents to route requests from the same session to the same endpoint.
307307

308308
> [!NOTE]
309309
> Session awareness in load-balanced pools is being released first to the **AI Gateway Early** [update group](configure-service-update-settings.md).
@@ -312,7 +312,7 @@ With any of the preceding load balancing options, you can enable **session aware
312312

313313
When you use session awareness, the client must handle cookies appropriately. The client needs to store the `Set-Cookie` header value and send it with subsequent requests to maintain session state.
314314

315-
You can use API Management policies to help set cookies for session awareness. For example, for the case of the Assistants API (a feature of [Azure OpenAI in Microsoft Foundry Models](/azure/ai-services/openai/concepts/models)), the client needs to keep the session ID, extract the thread ID from the body, and keep the pair and send the right cookie for each call. Moreover, the client needs to know when to send a cookie or when not to send a cookie header. These requirements can be handled appropriately by defining the following example policies:
315+
You can use API Management policies to help set cookies for session awareness. For example, in the case of the Assistants API (a feature of [Azure OpenAI in Microsoft Foundry Models](/azure/ai-services/openai/concepts/models)), the client needs to keep the session ID, extract the thread ID from the body, and keep the pair and send the right cookie for each call. Moreover, the client needs to know when to send a cookie or when not to send a cookie header. These requirements can be handled appropriately by defining the following example policies:
316316

317317

318318
```xml
@@ -440,6 +440,30 @@ This example includes an optional `sessionAffinity` pool configuration for sessi
440440

441441
---
442442

443+
## Context.Backend variable
444+
When you configure a backend entity in API Management, you can access backend properties in policies by using the `context.Backend` [context variable](api-management-policy-expressions.md#ContextVariables).
445+
446+
The following table lists the properties of the `context.Backend` variable.
447+
448+
| Property | Description |
449+
|----------|-------------|
450+
| `Id` | The resource identifier of the backend entity. |
451+
| `Type` | The type of the backend: `Single` or `Pool`.|
452+
| `AzureRegion` | The backend region, if specified. |
453+
454+
### Example
455+
456+
The following example shows how to set a custom header with the backend type in an inbound policy:
457+
458+
```xml
459+
<inbound>
460+
<base />
461+
<set-backend-service backend-id="my-backend" />
462+
<set-header name="X-Backend-Type" exists-action="override">
463+
<value>@(context.Backend?.Type ?? "n/a")</value>
464+
</set-header>
465+
</inbound>
466+
```
443467

444468
## Limitations
445469

articles/app-service/includes/tutorial-connect-msi-azure-database/code-sql-mi.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,28 +79,27 @@ For more information, see [Connect using Microsoft Entra authentication](/sql/co
7979
8080
1. Install dependencies.
8181
```bash
82-
python -m pip install pyodbc
82+
python -m pip install mssql-python python-dotenv
8383
```
8484
8585
1. Get the Azure SQL Database connection configurations from the environment variable added by Service Connector. Uncomment the part of the code snippet for the authentication type you want to use.
8686
```python
87-
import os;
88-
import pyodbc
87+
import os
88+
from mssql_python import connect
8989
9090
server = os.getenv('AZURE_SQL_SERVER')
9191
port = os.getenv('AZURE_SQL_PORT')
9292
database = os.getenv('AZURE_SQL_DATABASE')
93-
authentication = os.getenv('AZURE_SQL_AUTHENTICATION') # The value should be 'ActiveDirectoryMsi'
9493
9594
# Uncomment the following lines according to the authentication type.
9695
# For system-assigned managed identity.
97-
# connString = f'Driver={{ODBC Driver 18 for SQL Server}};Server={server},{port};Database={database};Authentication={authentication};Encrypt=yes;'
96+
# connection_string = f'Server={server},{port};Database={database};Authentication=ActiveDirectoryMSI;Encrypt=yes;'
9897
9998
# For user-assigned managed identity.
10099
# client_id = os.getenv('AZURE_SQL_USER')
101-
# connString = f'Driver={{ODBC Driver 18 for SQL Server}};Server={server},{port};Database={database};UID={client_id};Authentication={authentication};Encrypt=yes;'
100+
# connection_string = f'Server={server},{port};Database={database};UID={client_id};Authentication=ActiveDirectoryMSI;Encrypt=yes;'
102101
103-
conn = pyodbc.connect(connString)
102+
conn = connect(connection_string)
104103
```
105104
For an alternative method, you can also connect to Azure SQL Database using an access token, refer to [Migrate a Python application to use passwordless connections with Azure SQL Database](/azure/azure-sql/database/azure-sql-passwordless-migration-python).
106105

articles/app-service/troubleshoot-intermittent-outbound-connection-errors.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ Although PHP doesn't support connection pooling, you can try using persistent da
103103
* [MySQL](https://dev.mysql.com/doc/connector-python/en/connector-python-connection-pooling.html)
104104
* [MariaDB](https://mariadb.com/docs/connectors/mariadb-connector-python/api/pool/)
105105
* [PostgreSQL](https://www.psycopg.org/docs/pool.html)
106-
* [Pyodbc](https://github.com/mkleehammer/pyodbc/wiki/The-pyodbc-Module#pooling)
106+
* [mssql-python](https://github.com/microsoft/mssql-python) (recommended for SQL Server)
107107
* [SQLAlchemy](https://docs.sqlalchemy.org/en/20/core/pooling.html)
108108

109109
HTTP connection pooling

0 commit comments

Comments
 (0)