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
Copy file name to clipboardExpand all lines: articles/redis/aspnet.md
+14-14Lines changed: 14 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,32 +1,34 @@
1
1
---
2
2
title: Create an ASP.NET web app with an Azure Managed Redis cache
3
-
description: In this quickstart, you learn how to create an ASP.NET Core web app with an Azure Redis cache.
3
+
description: In this quickstart, you learn how to create an ASP.NET Core web app with an Azure Managed Redis cache.
4
4
ms.date: 01/30/2026
5
5
ms.topic: quickstart
6
6
ms.devlang: csharp
7
7
zone_pivot_groups: redis-type
8
8
appliesto:
9
-
- ✅ Azure Cache for Redis
10
-
# Customer intent: As an ASP.NET developer, new to Azure Redis, I want to create a new Node.js app that uses Azure Managed Redis or Azure Cache for Redis.
9
+
- ✅ Azure Managed Redis
10
+
# Customer intent: As an ASP.NET developer, new to Azure Managed Redis, I want to create a new .NET app that uses Azure Managed Redis.
11
11
---
12
12
13
13
# Azure Managed Redis sample - ASP.NET Core Web API
14
14
15
15
This sample shows how to connect an ASP.NET Core Web API to Azure Managed Redis by using Microsoft Entra ID authentication with the `DefaultAzureCredential` flow. The application avoids traditional connection string-based authentication in favor of token-based, Microsoft Entra ID access, which aligns with modern security best practices.
16
16
17
-
## Overview
18
-
19
17
The application is a minimal ASP.NET Core 8.0 Web API that:
20
18
21
19
1. Establishes a secure, authenticated connection to Azure Managed Redis at startup.
22
20
1. Exposes a simple REST endpoint that reads and writes data to the cache.
23
21
1. Demonstrates proper Redis connection lifecycle management by using dependency injection.
24
22
23
+
## Skip to the code on GitHub
24
+
25
+
Clone the [Microsoft.Azure.StackExchangeRedis](https://github.com/Azure/Microsoft.Azure.StackExchangeRedis/tree/main/sample.aspnet) repo on GitHub.
- An **Azure Managed Redis** instance provisioned in your Azure subscription
29
-
- Your Azure user or service principal must have the appropriate **Data Access Policy** assigned on the Redis resource, such as `Data Owner`, `Data Contributor`, or a custom policy with read and write permissions
31
+
- Your Azure user or service principal must be added as a Redis user on the cache. In the Azure portal, go to **Authentication** on the Resource menu, select **User or service principal**, and add your identity.
30
32
-[Azure CLI](https://docs.microsoft.com/cli/azure/install-azure-cli) for local development authentication
31
33
32
34
## Required NuGet Packages
@@ -77,9 +79,9 @@ The `DefaultAzureCredential` automatically picks up your Azure CLI credentials a
77
79
78
80
In Azure-hosted environments such as App Service, Container Apps, and AKS, `DefaultAzureCredential` uses:
79
81
80
-
-**Managed Identity**(system-assigned or user-assigned)
81
-
-**Workload Identity**(for Kubernetes scenarios)
82
-
-**Environment variables**(for service principal authentication)
82
+
-**Managed Identity**- system-assigned or user-assigned
83
+
-**Workload Identity**- for Kubernetes scenarios
84
+
-**Environment variables**- for service principal authentication
83
85
84
86
You don't need to change your code. The same `DefaultAzureCredential` seamlessly adapts to the environment.
|`No connection is available`| Verify the endpoint format and port (`10000`). Make sure the Redis instance is provisioned and accessible. |
189
-
|`AuthenticationFailedException`| Run `az login` to refresh credentials. Verify your identity has the required Data Access Policy on the Redis resource. |
190
-
|`Unauthorized`| Ensure your Microsoft Entra ID identity is assigned to a data access role on the Azure Managed Redis instance. |
191
+
|`AuthenticationFailedException`| Run `az login` to refresh credentials. Verify your identity is added as a Redis user under **Authentication**on the Resource menu. |
192
+
|`Unauthorized`| Ensure your Microsoft Entra ID identity is added as a Redis user on the Azure Managed Redis instance. For more information, see [Use Microsoft Entra ID for cache authentication](entra-for-authentication.md). |
-[Microsoft Entra ID authentication for Azure Cache for Redis](https://learn.microsoft.com/azure/azure-cache-for-redis/cache-azure-active-directory-for-authentication)
196
+
-[Microsoft Entra ID authentication for Azure Managed Redis](entra-for-authentication.md)
Copy file name to clipboardExpand all lines: articles/redis/dotnet.md
+61-56Lines changed: 61 additions & 56 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,56 +4,62 @@ description: In this quickstart, learn how to use Azure Managed Redis in a .NET
4
4
ms.date: 01/30/2026
5
5
ms.topic: quickstart
6
6
ms.devlang: csharp
7
-
zone_pivot_groups: redis-type
8
7
appliesto:
9
8
- ✅ Azure Managed Redis
10
9
# Customer intent: As a .NET developer, new to Azure Managed Redis, I want to create a new dotnet app that uses Azure Managed Redis.
11
10
---
12
11
13
-
# Quickstart: Use Azure Redis in .NET Core
12
+
# Quickstart: Use Azure Managed Redis in .NET Core
14
13
15
-
This is a .NET 8 console application that demonstrates how to connect to **Azure Managed Redis** using **Microsoft Entra ID** authentication. The core value proposition is **passwordless authentication** with automatic token refresh, providing a secure and modern approach to Redis connectivity.
14
+
This .NET 8 console application demonstrates how to connect to **Azure Managed Redis**by using **Microsoft Entra ID** authentication. The core value proposition is **passwordless authentication** with automatic token refresh, providing a secure and modern approach to Redis connectivity.
16
15
17
16
## Skip to the code on GitHub
18
17
19
-
Clone the repo [Microsoft.Azure.StackExchangeRedis](https://github.com/Azure/Microsoft.Azure.StackExchangeRedis/tree/main/sample) on GitHub.
18
+
Clone the [Microsoft.Azure.StackExchangeRedis](https://github.com/Azure/Microsoft.Azure.StackExchangeRedis/tree/main/sample) repo on GitHub.
- An **Azure Managed Redis** instance provisioned in your Azure subscription
24
+
- Your Azure user or service principal must be added as a Redis user on the cache. In the Azure portal, go to **Authentication** on the Resource menu, select **User or service principal**, and add your identity.
25
+
-[Azure CLI](https://docs.microsoft.com/cli/azure/install-azure-cli) for local development authentication
20
26
21
27
## Required NuGet Packages
22
28
23
-
| Package | Purpose |
24
-
|||
25
-
|`Microsoft.Azure.StackExchangeRedis`| Extension library that adds Entra ID authentication to StackExchange.Redis |
26
-
|`Azure.Identity`| Provides `DefaultAzureCredential` and other Azure identity implementations |
27
-
|`StackExchange.Redis`| The underlying Redis client (pulled in as a dependency) |
28
-
|`Microsoft.Extensions.Logging.Console`| Console logging for diagnostics |
|`Microsoft.Azure.StackExchangeRedis`| Extension library that adds Microsoft Entra ID authentication to StackExchange.Redis |
32
+
|`Azure.Identity`| Provides `DefaultAzureCredential` and other Azure identity implementations|
33
+
|`StackExchange.Redis`| The underlying Redis client (pulled in as a dependency)|
34
+
|`Microsoft.Extensions.Logging.Console`| Console logging for diagnostics |
29
35
30
-
## Authentication Methods
36
+
## Authentication methods
31
37
32
38
The extension supports multiple identity types, each with a corresponding `ConfigureForAzure*()` extension method:
33
39
34
-
1.**`DefaultAzureCredential`**— The recommended approach. It chains multiple credential sources (environment variables, managed identity, Azure CLI login, Visual Studio credentials, etc.) and uses the first one that works. Ideal for code that runs both locally and in Azure.
40
+
1.**`DefaultAzureCredential`**- The recommended approach. It chains multiple credential sources (environment variables, managed identity, Azure CLI authentication, Visual Studio credentials, and more) and uses the first one that works. It's ideal for code that runs both locally and in Azure.
35
41
36
-
2.**User-Assigned Managed Identity**— For Azure-hosted apps where you explicitly specify which managed identity to use via its client ID.
42
+
1.**User-Assigned Managed Identity**- For Azure-hosted apps where you explicitly specify which managed identity to use by providing its client ID.
37
43
38
-
3.**System-Assigned Managed Identity**— For Azure-hosted apps using the identity automatically assigned to the resource.
44
+
1.**System-Assigned Managed Identity**- For Azure-hosted apps that use the identity automatically assigned to the resource.
39
45
40
-
4.**Service Principal (Secret)**— Client ID + Tenant ID + secret for automated/CI scenarios.
46
+
1.**Service Principal (Secret)**- Client ID, tenant ID, and secret for automated or CI scenarios.
41
47
42
-
5.**Service Principal (Certificate)**— Client ID + Tenant ID + X.509 certificate for higher security.
48
+
1.**Service Principal (Certificate)**- Client ID, tenant ID, and X.509 certificate for higher security.
43
49
44
-
### How `DefaultAzureCredential`Works Locally
50
+
### How `DefaultAzureCredential`works locally
45
51
46
-
When developing locally, `DefaultAzureCredential`will attempt to authenticate using:
52
+
When you develop locally, `DefaultAzureCredential`attempts to authenticate by using the following methods:
47
53
48
54
```bash
49
55
az login
50
56
```
51
57
52
-
This signs you into the Azure CLI with your Microsoft Entra ID account. The SDK detects your cached credentials and uses them to obtain tokens. Your Entra ID user must be configured as a **Redis User** on the Azure Managed Redis resource via the **Data Access Configuration**blade in the Azure portal.
58
+
This method signs you in to the Azure CLI by using your Microsoft Entra ID account. The SDK detects your cached credentials and uses them to obtain tokens. You must configure your Microsoft Entra ID user as a **Redis User** on the Azure Managed Redis resource through the **Authentication**on the Resource menu in the Azure portal.
|`ConnectionMultiplexer`| Singleton, thread-safe connection pool to Redis. Create it once and reuse it for the app lifetime. |
127
+
|`IDatabase`| Interface for executing commands (`StringGet`, `StringSet`, `HashGet`, and so on). |
128
+
| Endpoint format |`endpoint:10000` (TLS) for Azure Managed Redis. |
124
129
125
-
## Running the Sample
130
+
## Running the sample
126
131
127
132
```powershell
128
133
az login
129
134
cd sample
130
135
dotnet run
131
136
```
132
137
133
-
Enter your Redis endpoint (e.g., <myredis.redis.azure.net:1000>), choose authentication method **1** (DefaultAzureCredential), and watch the `+` characters print every second as commands succeed. Let it run for 60+ minutes to verify automatic token refresh works.
138
+
Enter your Redis endpoint (for example, `<myredis.redis.azure.net:1000>`), choose authentication method **1** (DefaultAzureCredential), and watch the `+` characters print every second as commands succeed. Let it run for more than 60 minutes to verify automatic token refresh works.
134
139
135
-
## Production Considerations
140
+
## Production considerations
136
141
137
-
| Setting | Sample Value| Production Value|
138
-
||--||
139
-
|`AbortOnConnectFail`|`true`|`false` (retry on startup) |
140
-
|`BacklogPolicy`|`FailFast`|`Default` (queue commands during transient failures) |
141
-
| Connection lifetime | Demo loop | Singleton via DI (`IConnectionMultiplexer`) |
|`AbortOnConnectFail`|`true`|`false` (retry on startup)|
145
+
|`BacklogPolicy`|`FailFast`|`Default` (queue commands during transient failures) |
146
+
| Connection lifetime | Demo loop | Singleton via DI (`IConnectionMultiplexer`)|
142
147
143
148
This sample provides a complete reference implementation for secure, passwordless Entra ID authentication in any .NET application that uses Azure Managed Redis.
Copy file name to clipboardExpand all lines: articles/redis/entra-for-authentication.md
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -46,7 +46,7 @@ If you have used access keys in the past for authentication, you need to update
46
46
47
47
### Microsoft Entra client workflow
48
48
49
-
1. Configure your client application to acquire a Microsoft Entra token for scope, `https://redis.azure.com/.default`, or `acca5fbb-b7e4-4009-81f1-37e38fd66d78/.default`, by using the[Microsoft Authentication Library (MSAL)](/azure/active-directory/develop/msal-overview).
49
+
1. Configure your client application to acquire a Microsoft Entra token for scope, `https://redis.azure.com/.default`, or `acca5fbb-b7e4-4009-81f1-37e38fd66d78/.default`, by using the[Microsoft Authentication Library (MSAL)](/azure/active-directory/develop/msal-overview).
50
50
51
51
1. Update your Redis connection logic to use the following `User` and `Password`:
52
52
@@ -106,13 +106,13 @@ To disable access keys, follow this procedure:
106
106
107
107
1. In the Azure portal, select the Azure Managed Redis instance where you want to disable access keys.
108
108
109
-
1. On the **Resource** menu, select**Authentication**.
109
+
1. On the **Resource** menu, select**Authentication**.
110
110
111
-
1. On the working pane, select**Access keys**.
111
+
1. On the working pane, select**Access keys**.
112
112
113
113
1. Select the **Access Keys Authentication** control to disable access keys.
114
114
115
-
1. Confirm that you want to update your configuration by selecting**Yes**.
115
+
1. Confirm that you want to update your configuration by selecting**Yes**.
116
116
117
117
> [!IMPORTANT]
118
118
> When the **Access Keys Authentication** setting is changed for a cache, all existing client connections, using access keys or Microsoft Entra, are terminated. Follow the best practices to implement proper retry mechanisms for reconnecting Microsoft Entra-based connections. For more information, see [Connection resilience](best-practices-connection.md).
0 commit comments