Reference to : Mapping an Azure File Service CloudFileShare as a virtual directory on each instance of a cloud service
I encounter an issue when I am trying to create a virtual directory in Azure Cloud Service, and the virtual directory is mapped to Azure file service.
What I have done
1) use <Runtime executionContext="elevated" />
for webrole in in ServiceDefinition.csdef
2) in WebRole.cs I mount the drive (as described in http://blogs.msdn.com/b/windowsazurestorage/archive/2014/05/27/persisting-connections-to-microsoft-azure-files.aspx for PaaS) I also do it in application start.
public static void MountShare(string shareName,
string driveLetterAndColon,
string username,
string password)
{
if (!String.IsNullOrEmpty(driveLetterAndColon))
{
// Make sure we aren't using this driveLetter for another mapping
WNetCancelConnection2(driveLetterAndColon, 0, true);
}
NETRESOURCE nr = new NETRESOURCE();
nr.dwType = ResourceType.RESOURCETYPE_DISK;
nr.lpRemoteName = shareName;
nr.lpLocalName = driveLetterAndColon;
int result = WNetAddConnection2(nr, password, username, 0);
if (result != 0 || result != 85)
//85 indicates the drive name is already used. in this scenario, it means the drive is already mapped.
{
throw new Exception("WNetAddConnection2 failed with error " + result);
}
}
3) In WebRole.cs, I create the virtual directories by the following,
app.VirtualDirectories.Add("/asset/cms", @"s:\cms");
4) In WebRole.cs, I use the following to make the AppPool run in the admin account I created for remote desktop,
applicationPool.ProcessModel.IdentityType = ProcessModelIdentityType.SpecificUser;
applicationPool.ProcessModel.UserName = appPoolUser;
applicationPool.ProcessModel.Password = appPoolPass;
applicationPool.ProcessModel.LoadUserProfile = true;
Problem:
I am unable to get anything from /asset/cms. It comes back with 500.19 if I try to access the files inside, and it says 'The requested page cannot be accessed because the related configuration data for the page is invalid.', and specifically it points to s:\cms\web.config which does not exist. When I remote to the cloud service instance, and open IIS mgr, I can see the virtual directories are created correctly.
I guess it's a permission problem. But I am not able to edit permission of the virtual directory since it's mapped to a network drive.
How can I solve this problem? -- Now the above problem is solved and the cloud service can access the file service share. But, new problem - is it possible to use the network_service identity to run the AppPool?