2017-05-22 7 views
0

私はASP Web APIを持っており、そこから呼び出してファイルを返そうとしています。ファイルの読み取り時にUnauthorizedAccessExceptionが発生しました

System.UnauthorizedAccessException: Access to the path 'E:\Data\Docs\specific\document.pdf' 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, Boolean checkHost)
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) at GIS.Backend.Assets.BLL.Document.GetByUrl(String url) at GIS.Backend.Assets.WebApi.Controllers.DocumentController.Get(String url)

私はそれがうまくいかないところ、これは推測している:私は「ドキュメントへの読み取りアクセスを持つようにIIS_IUSRSを設定している

string documentenPath = System.Web.Configuration.WebConfigurationManager.AppSettings["DocumentenDir"].ToString(); 
     string fullUrl = documentenPath + url; 

     Stream file = new FileStream(fullUrl, FileMode.Open); 
     return file; 

私のサーバー上で

は、私はエラーを得続けます'フォルダ、それは右を読むことができるはずですか?

+1

@MegaTronは、FileAccess.Readフラグでストリームを開きます。 – VDWWD

+1

FileAccess.Readフラグを使用してStreamを開き、これが機能するかどうかを確認できますか? –

+0

@AlkisGiamalisはい、これは私のためにやった!答えとして追加して、私はそれを受け入れます! – Firenter

答えて

2

は、それはウェブサイトのためだ

FileStream fs = new FileStream(fullUrl, FileMode.Open, FileAccess.Read); 
関連する問題