|
1 | 1 | ---
|
2 | 2 | title: Create an ASP.NET Core web app with Azure Cache for Redis
|
3 |
| -description: In this quickstart, you learn how to create an ASP.NET Core web app with Azure Cache for Redis |
| 3 | +description: In this quickstart, you learn how to create an ASP.NET Core web app with Azure Cache for Redis. |
4 | 4 | author: flang-msft
|
5 | 5 | ms.author: franlanglois
|
6 | 6 | ms.service: cache
|
7 | 7 | ms.devlang: csharp
|
8 | 8 | ms.custom: devx-track-csharp, mvc, mode-other
|
9 | 9 | ms.topic: quickstart
|
10 |
| -ms.date: 03/25/2022 |
| 10 | +ms.date: 04/24/2024 |
11 | 11 |
|
12 | 12 | ---
|
13 | 13 |
|
@@ -42,42 +42,41 @@ dotnet user-secrets set CacheConnection "<cache name>.redis.cache.windows.net,ab
|
42 | 42 |
|
43 | 43 | ## Connect to the cache with RedisConnection
|
44 | 44 |
|
45 |
| -The connection to your cache is managed by the `RedisConnection` class. The connection is made in this statement in `HomeController.cs` in the *Controllers* folder: |
| 45 | +The `RedisConnection` class manages the connection to your cache. The connection is made in this statement in `HomeController.cs` in the *Controllers* folder: |
46 | 46 |
|
47 | 47 | ```csharp
|
48 | 48 | _redisConnection = await _redisConnectionFactory;
|
49 | 49 | ```
|
50 | 50 |
|
51 |
| -In `RedisConnection.cs`, you see the `StackExchange.Redis` namespace has been added to the code. This is needed for the `RedisConnection` class. |
| 51 | +In `RedisConnection.cs`, you see the `StackExchange.Redis` namespace is added to the code. This is needed for the `RedisConnection` class. |
52 | 52 |
|
53 | 53 | ```csharp
|
54 | 54 | using StackExchange.Redis;
|
55 | 55 | ```
|
56 | 56 |
|
57 |
| -The `RedisConnection` code ensures that there is always a healthy connection to the cache by managing the `ConnectionMultiplexer` instance from `StackExchange.Redis`. The `RedisConnection` class recreates the connection when a connection is lost and unable to reconnect automatically. |
| 57 | +The `RedisConnection` code ensures that there's always a healthy connection to the cache by managing the `ConnectionMultiplexer` instance from `StackExchange.Redis`. The `RedisConnection` class recreates the connection when a connection is lost and unable to reconnect automatically. |
58 | 58 |
|
59 | 59 | For more information, see [StackExchange.Redis](https://stackexchange.github.io/StackExchange.Redis/) and the code in a [GitHub repo](https://github.com/StackExchange/StackExchange.Redis).
|
60 | 60 |
|
61 |
| -<!-- :::code language="csharp" source="~/samples-cache/quickstart/aspnet-core/ContosoTeamStats/RedisConnection.cs"::: --> |
62 |
| - |
63 | 61 | ## Layout views in the sample
|
64 | 62 |
|
65 | 63 | The home page layout for this sample is stored in the *_Layout.cshtml* file. From this page, you start the actual cache testing by clicking the **Azure Cache for Redis Test** from this page.
|
66 | 64 |
|
67 |
| -1. Open *Views\Shared\\_Layout.cshtml*. |
| 65 | +1. Open *Views\Shared\\_Layout.cshtml*. |
68 | 66 |
|
69 | 67 | 1. You should see in `<div class="navbar-header">`:
|
70 | 68 |
|
71 | 69 | ```html
|
72 | 70 | <a class="navbar-brand" asp-area="" asp-controller="Home" asp-action="RedisCache">Azure Cache for Redis Test</a>
|
73 | 71 | ```
|
| 72 | + |
74 | 73 | :::image type="content" source="media/cache-web-app-aspnet-core-howto/cache-welcome-page.png" alt-text="screenshot of welcome page":::
|
75 | 74 |
|
76 | 75 | ### Showing data from the cache
|
77 | 76 |
|
78 | 77 | From the home page, you select **Azure Cache for Redis Test** to see the sample output.
|
79 | 78 |
|
80 |
| -1. In **Solution Explorer**, expand the **Views** folder, and then right-click the **Home** folder. |
| 79 | +1. In **Solution Explorer**, expand the **Views** folder, and then right-click the **Home** folder. |
81 | 80 |
|
82 | 81 | 1. You should see this code in the *RedisCache.cshtml* file.
|
83 | 82 |
|
@@ -124,40 +123,23 @@ From the home page, you select **Azure Cache for Redis Test** to see the sample
|
124 | 123 | ```dos
|
125 | 124 | dotnet build
|
126 | 125 | ```
|
127 |
| - |
| 126 | + |
128 | 127 | 1. Then run the app with the following command:
|
129 | 128 |
|
130 | 129 | ```dos
|
131 | 130 | dotnet run
|
132 | 131 | ```
|
133 |
| - |
| 132 | + |
134 | 133 | 1. Browse to `https://localhost:5001` in your web browser.
|
135 | 134 |
|
136 | 135 | 1. Select **Azure Cache for Redis Test** in the navigation bar of the web page to test cache access.
|
137 | 136 |
|
138 | 137 | :::image type="content" source="./media/cache-web-app-aspnet-core-howto/cache-simple-test-complete-local.png" alt-text="Screenshot of simple test completed local":::
|
139 | 138 |
|
140 |
| -## Clean up resources |
141 |
| - |
142 |
| -If you continue to use this quickstart, you can keep the resources you created and reuse them. |
143 |
| - |
144 |
| -Otherwise, if you're finished with the quickstart sample application, you can delete the Azure resources that you created in this quickstart to avoid charges. |
145 |
| - |
146 |
| -> [!IMPORTANT] |
147 |
| -> Deleting a resource group is irreversible. When you delete a resource group, all the resources in it are permanently deleted. Make sure that you do not accidentally delete the wrong resource group or resources. If you created the resources for hosting this sample inside an existing resource group that contains resources you want to keep, you can delete each resource individually on the left instead of deleting the resource group. |
148 |
| - |
149 |
| -### To delete a resource group |
150 |
| - |
151 |
| -1. Sign in to the [Azure portal](https://portal.azure.com), and then select **Resource groups**. |
152 |
| - |
153 |
| -1. In the **Filter by name...** box, type the name of your resource group. The instructions for this article used a resource group named *TestResources*. On your resource group, in the results list, select **...**, and then select **Delete resource group**. |
154 |
| - |
155 |
| - :::image type="content" source="media/cache-web-app-howto/cache-delete-resource-group.png" alt-text="Delete"::: |
156 |
| - |
157 |
| -1. You're asked to confirm the deletion of the resource group. Type the name of your resource group to confirm, and then select **Delete**. |
| 139 | +<!-- Clean up include --> |
| 140 | +[!INCLUDE [cache-delete-resource-group](includes/cache-delete-resource-group.md)] |
158 | 141 |
|
159 |
| -After a few moments, the resource group and all of its resources are deleted. |
| 142 | +## Related content |
160 | 143 |
|
161 |
| -## Next steps |
162 | 144 | - [Connection resilience](cache-best-practices-connection.md)
|
163 | 145 | - [Best Practices Development](cache-best-practices-development.md)
|
0 commit comments