System.IO options in Azure Web App

MS Techie 2,681 Reputation points
2021-02-24T18:47:08.7+00:00

i am planning to migrate my on-premises ASP.Net 4.5 Website to Azure Web App
In my on-premises website, we have used the MemoryStream for in-memory storage and StreamReader to read from that MemoryStream . Both of them belong to the System.IO namespace , which is not allowed in Azure Web App.

What alternatives do i have in Azure App Service , instead of MemoryStream and StreamReader ?
Should i use Redis Cache or any other alternatives ?

Please help

Azure Cache for Redis
Azure Cache for Redis
An Azure service that provides access to a secure, dedicated Redis cache, managed by Microsoft.
217 questions
Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
6,956 questions
0 comments No comments
{count} votes

Accepted answer
  1. KalyanChanumolu-MSFT 8,316 Reputation points
    2021-02-25T04:44:34.33+00:00

    @MS Techie You can use the System.IO namespace in an Azure Web App.
    Below is a code snippet that uses MemoryStream to upload a blob to Azure Storage.

    using System;  
    using Azure.Storage.Blobs;  
    using Azure.Storage.Blobs.Models;  
    using System.Collections.Generic;  
    using System.Threading.Tasks;  
    using System.Text;  
    using System.IO;  
    using Azure.Identity;  
      
    // Some code omitted for brevity.  
      
    static public async Task UploadBlob(string accountName, string containerName, string blobName, string blobContents)  
    {  
        // Construct the blob container endpoint from the arguments.  
        string containerEndpoint = string.Format("https://{0}.blob.core.windows.net/{1}",  
                                                    accountName,  
                                                    containerName);  
      
        // Get a credential and create a client object for the blob container.  
        BlobContainerClient containerClient = new BlobContainerClient(new Uri(containerEndpoint),  
                                                                        new DefaultAzureCredential());  
      
        try  
        {  
            // Create the container if it does not exist.  
            await containerClient.CreateIfNotExistsAsync();  
      
            // Upload text to a new block blob.  
            byte[] byteArray = Encoding.ASCII.GetBytes(blobContents);  
      
            using (MemoryStream stream = new MemoryStream(byteArray))  
            {  
                await containerClient.UploadBlobAsync(blobName, stream);  
            }  
        }  
        catch (Exception e)  
        {  
            throw e;  
        }  
    }  
    

    We have the complete tutorial here
    Do let us know if you have any further questions.

    ----------

    If an answer is helpful, please "Accept answer" or "Up-Vote" for the same which might be beneficial to other community members reading this thread.


0 additional answers

Sort by: Most helpful