我有一个 ASP.NET 应用程序,需要从 Azure 文件共享读取和写入。我无法直接在 Azure Fileshare 上设置权限,而是拥有存储帐户 key 和主访问 key 。
我可以进入我的服务器并使用“net use”命令将文件共享安装为驱动器。因为对previous question的回答,我知道 ASP.NET 将无法看到已安装的驱动器。
我能够在本地计算机上运行此功能,在本地用户下运行 IIS 并将 azure 存储帐户文件共享添加到凭据管理器,但这在服务器上不起作用,因此我缺少一些拼图的一部分。
在服务器上,如果我尝试使用访问共享
Directory.Exists(@"\\storageaccountkey.file.core.windows.net\sharename");
这在 ASP.NET 中不起作用(我怀疑这是因为 ASP.NET 无法对共享进行身份验证)。从 LINQpad 运行此代码确实有效并返回 true。
我尝试将凭据添加到凭据管理器,并在运行凭据管理器的用户下运行我的应用程序池,但我仍然从 Directory.Exists() 返回“false”。
为什么我看不到服务器上的目录?
最佳答案
建议您使用Storage Client Library来访问文件共享,查看官方文章https://azure.microsoft.com/en-us/documentation/articles/storage-dotnet-how-to-use-files/
您可以使用下面的代码代替 Directory.Exists 来访问共享:
// Parse the connection string for the storage account.
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(Microsoft.Azure.CloudConfigurationManager.GetSetting("StorageConnectionString"));
// Create a CloudFileClient object for credentialed access to File storage.
CloudFileClient fileClient = storageAccount.CreateCloudFileClient();
// Get a reference to the file share we created previously.
CloudFileShare share = fileClient.GetShareReference("logs");
// Ensure that the share exists.
if (share.Exists())
{
//do something
}
关于c# - 从 ASP.NET 应用程序访问 Azure 存储帐户文件共享,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35759421/