0

I have an MVC web application hosted on Azure as a cloud service which stores file locally on the role environment. This was a viable solution until moving the service to high availability with two instances but now the files are only written to the environment on which they were uploaded and so if the user jumps to the other instance due to the load balancer these files become unavailable.

Is there any means of writing to the other role environment of instance[1] if I am logged into instance[0]. The sessions are stored across both instances using Redis cache. Currently my code to write to the role enrvironment is as follows:

public static string ImportContentPackage(string iEnVar, string fileName, HttpPostedFileBase zipFile, string companyName)
{
  //Get the Local Storage place.
  LocalResource tempDirectory = RoleEnvironment.GetLocalResource("TempZipDirectory");

  //Now System.IO to store the Zip file in there. Get the file name without the extension.
  string actualFileName = fileName.Split('.')[0];

  System.IO.Directory.CreateDirectory(tempDirectory.RootPath + "\\" + companyName + "\\" + actualFileName); 

  string holderDir = tempDirectory.RootPath + @"\" + companyName + @"\" + actualFileName;

  try
  {
    //Clear out any directories that might be there.
    CleanImportDirectory(holderDir);

    //Save the zip into the package to enable unzipping.
    BinaryReader br = new BinaryReader(zipFile.InputStream);
    File.WriteAllBytes(tempDirectory.RootPath + "\\" + fileName, br.ReadBytes(zipFile.ContentLength));


    // Unzip the content package into a local directory for processing
    SCORM.Validation.Handlers.UnZipFile uzh = new SCORM.Validation.Handlers.UnZipFile(tempDirectory.RootPath + "\\" + fileName, holderDir);

    SCORM.Validation.Helpers.Result result = uzh.Extract();

    if(result.PackageCheckerMessages.Count > 0)
    {
      holderDir = "";
    }
  }
  catch (System.NullReferenceException npe)
  {
  }
  return holderDir;
}

The LocalResource tempDirecory variable should be the same on both instances as in that they are both named TempZipDirectory.

Jay
  • 3,012
  • 14
  • 48
  • 99

1 Answers1

-1

Is now possible with Azure Files. http://fabriccontroller.net/blog/posts/using-the-azure-file-service-in-your-cloud-services-web-roles-and-worker-role/

  • It is a requirement that the files remain in their folder structure and blob storage flat storage has been ruled out. The question makes perfect sense, I am asking if it possible to write to another instance from within another instance in a high availability set up – Jay Jul 23 '14 at 09:29
  • I guess these guys are wasting their time maybe you should phone microsoft and tell them http://blogs.msdn.com/b/windowsazurestorage/archive/2011/04/16/using-smb-to-share-a-windows-azure-drive-among-multiple-role-instances.aspx – Jay Jul 23 '14 at 09:42
  • 1
    You should look into Azure File Service which is currently in preview. Basically what you will do is have a share in Azure File Service which gets mapped to both instances and then whenever you write from any instance, it gets stored in one common place. – Gaurav Mantri Jul 23 '14 at 09:56
  • Hi Guarav I was hoping to use this but it is not available in preview for my subscription – Jay Jul 23 '14 at 09:57
  • Aah ... have you requested to enable this service in your subscription? From what I have heard, it takes a few weeks for Azure team to enable it. – Gaurav Mantri Jul 23 '14 at 09:58