Integrate Blob Storage into a Web App
Learn On Demand
Learn On Demand Pro Series

Time
1 hour
Difficulty
Intermediate

In this IT Pro Challenges hands-on lab, learners are introduced to skills required to integrate Blob storage into a web app. Exercises in this lab teach users how to generate shared access signatures, Blob, and file links. The topics covered in this lab are critical for learners to be effective in a developer, database administrator job roles in IT...

Become one of the 3 million IT and Cyber professionals advancing their careers

Sign up with
Or

Already have an account? Sign In »

Overview

Azure Blob storage is used for collecting large unorganized data such as text or binary data. It can be used to display data openly to the world, or to save application data confidentially.

In this hands-on lab, you will write code to create containers with public blob access and private blob access, and then upload test files to the containers. Next, you will write code to create a shared access signature (SAS) token for the private blob container, and then you will write code to retrieve the URLs of the uploaded files. Finally, you will test the configuration using a test page provided with the web app.

Understand the Scenario

In this virtual lab, you are a developer for a company that is migrating its primary web app from its datacenter to Azure. You need to write code to access an Azure storage account used by the web app. For this challenge, you are provided with Visual Studio 2017 installed on a virtual machine. The ASP.NET MVC project for this challenge is in the D:\challenge folder on the virtual machine. All of the code that you will write will be in a single code file. You will use an Azure resource group that contains an Azure storage account. The configuration of the storage account may not be complete when you begin this challenge. You will receive a notification when the automated configuration is complete.

Configure your environment

In this section of the lab, learners will first configure the environment. First, they will sign in to the Azure portal and record the storage account name and the storage account key. Next, they will open a Remote Desktop Client connection to the virtual machine and open the challenge project at D:\challenge\AzureStorageDevelopment.sln. Finally, they will open web.config, and then set the TestType appSetting to "3" and in web.config, set the StorageAccount and open the Models\StorageContext.cs file.

Upload files to the storage account

Blob storage is a characteristic in Microsoft Azure that allows developers to store unorganized data in Microsoft's cloud. This data can be obtained from anyplace and can combine audio, video, and text. Blobs are classified into "containers" that are attached to user accounts. After configuring the environment, in this section of the virtual lab, learners will upload files to the storage account. First, in the UploadFile method of the StorageContext class, they will write code to do the following:

  • Create a container identified by the containerName parameter if the container does not already exist.
  • Set the blob access level of the container using the isPrivate parameter.
  • Upload the file content in the fileData parameter. The structure of the BlobFileData class is described at the top of the file.

Next, they will test the application locally. The page should show that the public and private file uploads were successful. The SAS generation and downloads will fail at this point. Finally, they will deploy the project to the Azure web app.

Generate a shared access signature

A shared access signature (SAS) is a URI that allows restricted access licenses to Azure Storage resources. By sharing a distributed access signature URI to these clients, users can give them access to a device for a specified time, with a detailed set of permissions. In this section of the lab, learners will learn how to generate a shared access signature. First, they will code the GetSAS method of the StorageContext class to generate a read-only SAS for the container identified by the containerName parameter and make sure that the SAS is valid for at least 24 hours. Next, they will test the application locally. The page should show that the public and private file uploads were successful, and the SAS was generated successfully. The downloads will fail at this point. Finally, they will deploy the project to the Azure web app and verify that a shared access signature is generated.

Retrieve blob file link

In this section of the lab, learners will learn how to Retrieve blob file links. First, in the GetFileList method of the StorageContext class, they will write code to do the following:

  • Generate a SAS token for the container identified by the containerName parameter if the isPrivate parameter value is true.
  • Return a list of the BlobFileData objects representing the blob files in the containerName container. Set the Name, URL, and SAS properties of the BlobFileData objects.

Next, they will test the application locally. All operations should be successful at this point. Finally, they will deploy the project to the Azure web app and verify that files are downloaded from public blob storage and that files are downloaded from private blob storage.

Lab Summary Conclusion

After completing the "Integrate Blob Storage into a Web App" virtual lab, you will have accomplished the following:

  • Created an Azure storage blob container.
  • Uploaded files to a blob container.
  • Generated a shared access signature.
  • Enumerated the files in a blob storage container.