1

我们有一个部署到客户服务器的 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)

有谁知道如何让这个工作?

4

1 回答 1

2

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

File.Open(StoragePath, FileMode.Open, FileAccess.Read, FileShare.Read);
于 2013-07-16T11:02:07.683 回答