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.