参考: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.

我做了什么

1)在ServiceDefinition.csdef中使用 <Runtime executionContext="elevated" /> for webrole

2)在WebRole.cs中我安装了驱动器(如http://blogs.msdn.com/b/windowsazurestorage/archive/2014/05/27/persisting-connections-to-microsoft-azure-files.aspx中所描述的PaaS)我也在应用程序启动时执行此操作 .

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)在WebRole.cs中,我通过以下方式创建虚拟目录,

app.VirtualDirectories.Add("/asset/cms", @"s:\cms");

4)在WebRole.cs中,我使用以下命令使AppPool在我为远程桌面创建的管理员帐户中运行,

applicationPool.ProcessModel.IdentityType = ProcessModelIdentityType.SpecificUser;
applicationPool.ProcessModel.UserName = appPoolUser;
applicationPool.ProcessModel.Password = appPoolPass;
applicationPool.ProcessModel.LoadUserProfile = true;

Problem:

我无法从/ asset / cms获得任何东西 . It comes back with 500.19 如果我尝试访问里面的文件,它会显示' The requested page cannot be accessed because the related configuration data for the page is invalid. ',特别是它指向不存在的s:\ cms \ web.config . 当我远程访问 Cloud 服务实例并打开IIS mgr时,我可以看到正确创建了虚拟目录 .

我想这是一个许可问题 . 但是我无法编辑虚拟目录的权限,因为它已映射到网络驱动器 .

我怎么解决这个问题? - 现在解决了上述问题, Cloud 服务可以访问文件服务共享 . 但是,新问题 - 是否可以使用network_service标识来运行AppPool?