【问题标题】:How can I access a file that's part of the deployment in an Azure Webrole如何访问属于 Azure Webrole 中部署的文件
【发布时间】:2013-07-16 19:02:07
【问题描述】:

我们有一个部署到客户服务器的 WCF 服务,我们现在正在创建一个 webrole,使我们能够在 Azure 上运行相同的服务。 问题是服务项目有一个 img 文件夹,我们在其中存储了一些在文件丢失或作为徽标时使用的图像。当我们的服务尝试用这行代码访问这个文件时

File.Open(StoragePath, FileMode.Open);

我们得到以下异常:

System.UnauthorizedAccessException: Access to the path 'E:\sitesroot\0\bin\img\delficertwarning.tif' is denied.
 at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
 at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath)
 at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy)
 at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)

有谁知道如何让它工作?

【问题讨论】:

  • 被拒绝访问的代码运行的是什么用户?
  • 除了 Azure Webrole 的默认用户之外,我们还没有尝试过,尤其是在我们找到了仅使用读取访问权限的解决方案之后。

标签: c# azure file-io azure-web-roles


【解决方案1】:

事实证明,您必须指定仅使用打开的文件进行阅读:

File.Open(StoragePath, FileMode.Open, FileAccess.Read, FileShare.Read);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-11-18
    • 2013-10-22
    • 1970-01-01
    • 2012-03-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多