page_type | languages | name | description | products | ||||
---|---|---|---|---|---|---|---|---|
sample |
|
Quickstart: Use Azure Cache for Redis with an ASP.NET Core web app |
Learn how to use an ASP.NET Core web application to connect to Azure Cache for Redis to store and retrieve data from the cache. |
|
This sample shows you how to use an ASP.NET Core web application to connect to Azure Cache for Redis to store and retrieve data from the cache. See the accompanying article on the documentation site for details, including best practices and how to create the sample code from scratch.
- Azure subscription - create one for free
- Azure Cache for Redis cache - create one
- .NET Core SDK
Download the sample code to your development PC.
In your command window, change directories to the folder containing this sample.
Execute the following command to restore the packages:
dotnet restore
Execute the following command to store a new secret named CacheConnection, after replacing the placeholders (including angle brackets) for your cache name and primary access key:
dotnet user-secrets set CacheConnection "<cache name>.redis.cache.windows.net,abortConnect=false,ssl=true,allowAdmin=true,password=<primary-access-key>"
Execute the following command in your command window to build the app:
dotnet build
Run the app with the following command:
dotnet run
Browse to https://localhost:5001
in your web browser.
Select Azure Cache for Redis Test in the navigation bar of the web page to test cache access.