programing tip

경로에 대한 액세스가 거부되었습니다

itbloger 2020. 6. 7. 10:36
반응형

경로에 대한 액세스가 거부되었습니다


이 질문이 여기에서 여러 번 요청되었지만 내 문제에 대한 해결책을 찾을 수 없습니다. .net c #의 폴더에 이미지를 저장하려고하지만이 예외가 발생합니다.

Access to the path 'C:\inetpub\wwwroot\mysite\images\savehere' is denied.The error occured at mscorlib because    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)

이 폴더 (저장소) network serviceiis_iusrs에 대한 모든 권한을 부여 했으며 모든 권한을 부여 everyone했지만 여전히이 예외가 발생했습니다. 탐색기와 IIS 관리자를 통해 액세스를 시도했지만 여전히 운이 없습니다.

Windows Server 2008 R2 및 IIS 7.5에서 수행하고 있습니다. 누가 액세스 권한을 부여해야합니까?

감사


웹 사이트의 응용 프로그램 풀에서 웹 사이트에서 실행중인 ID (기본적으로이)가 무엇인지 Application Pool Identity확인하고 올바른 권한을 부여해야합니다.


'C : \ inetpub \ wwwroot \ mysite \ images \ savehere'경로에 대한 액세스가 거부되었습니다.

메시지를주의 깊게 읽으십시오. 디렉토리와 이름이 같은 파일에 저장하려고합니다. 작동하지 않습니다. 하나의 새 파일로 파일로 채워진 디렉토리를 덮어 쓸 수 없습니다. "경로에 대한 액세스가 거부되었습니다"라고 진단 할 수없는 데이터 손실이 발생할 수 있습니다.

예외 메시지는 이상적이지 않지만 OS에서 직접 제공되며 스톤으로 캐스팅됩니다. 프레임 워크는 종종 더 나은 메시지를 생성하기 위해 추가 검사를 추가하지만 이는 네트워크에서 값 비싼 테스트입니다. 성능도 기능입니다.

'C : \ inetpub \ wwwroot \ mysite \ images \ savehere \ mumble.jpg'와 같은 이름을 사용해야합니다. 경로 이름을 안정적으로 생성하려면 Path.Combine ()고려하십시오 .


서버에서 파일 (실제로는 템플릿의 사본 인 파일)을 만들려고 할 때 동일한 문제가 발생했습니다.

완전한 오류 메시지는 다음과 같습니다.

{ERROR} 08/07/2012 22:15:58 - System.UnauthorizedAccessException: Access to the path 'C:\inetpub\wwwroot\SAvE\Templates\Cover.pdf' is denied.

TemplatesIIS 앱 폴더 안에 새 폴더를 추가했습니다 . 필자의 경우 매우 중요한 것은 해당 폴더의 IUSR 사용자에게 쓰기 (Gravar) 권한을 부여해야한다는 것입니다. 당신은 또한 제공해야 할 수 있습니다 Network ServiceASP.NET v$.#같은 쓰기 권한.

여기에 이미지 설명을 입력하십시오

이 작업을 수행하면 모든 것이 예상대로 작동합니다.


나는 정확히 같은 문제가 있었다.

해결책은 액세스하려고했던 파일이 읽기 전용 인 템플릿 파일에서 복사되었으므로 읽기 전용이었습니다.

<페이스 팜 />


파일 이름을 설정하지 않고 파일을 저장하려고 할 때이 문제가 발생했습니다.

이전 코드

File.WriteAllBytes(@"E:\Folder", Convert.FromBase64String(Base64String));

작업 코드

File.WriteAllBytes(@"E:\Folder\"+ fileName, Convert.FromBase64String(Base64String));

내 문제는 읽기 권한 만 요청해야한다는 것입니다.

FileStream fs = new FileStream(name, FileMode.Open, FileAccess.Read);

please add IIS_IUSERS full control permission to your folder. you find this option from security tab in folder properties. 이 이미지에서이 옵션과 사용자를 찾으십시오


What Identity is your Application Pool for the Web application running as, to troubleshoot, try creating a new App Pool with say Network Service as its identity and make your web application use that new App Pool you created and see if the error persists.


The following tip isn't an answer to this thread's original question, but might help some other users who end up on this webpage, after making the same stupid mistake I just did...

I was attempting to get an ASP.Net FileUpload control to upload it's file to a network address which contained a "hidden share", namely:

\MyNetworkServer\c$\SomeDirectoryOrOther

I didn't understand it. If I ran the webpage in Debug mode in Visual Studio, it'd work fine. But when the project was deployed, and was running via an Application Pool user, it refused to find this network directory.

I had checked which user my IIS site was running under, gave this user full permissions to this directory on the "MyNetworkServer" server, etc etc, but nothing worked.

The reason (of course!) is that only Administrators are able to "see" these hidden drive shares.

My solution was simply to create a "normal" share to

\MyNetworkServer\SomeDirectoryOrOther

and this got rid of the "Access to the path... is denied" error. The FileUpload was able to successfully run the command

fileUpload.SaveAs(networkFilename);

Hope this helps some other users who make the same mistake I did !

Note also that if you're uploading large files (over 4Mb), then IIS7 requires that you modify the web.config file in two places. Click on this link to read what you need to do: Uploading large files in ASP.Net


I Solved with this setting:

IIS > Application Pools > [your site] > Advanced Settings... > Identity > Built-in accound > LocalSystem


My problem was something like that:

FileStream ms = new FileStream(path, FileMode.Open, FileAccess.ReadWrite);

but instead of using path I should use File.FullName... I don't know if it's going to help anyone else, just passing my own experience with this erro given!


  1. Change the setting from built-in account to custom account and enter the other server's username and password.

  2. Keep the setting as integrated (instead of classic mode).


Maybe it'il help you.

string tempDirectoryPath = @"C:\Users\HOPE\Desktop\Test Folder";
string zipFilePath = @"C:\Users\HOPE\Desktop\7za920.zip";
Directory.CreateDirectory(tempDirectoryPath);
ZipFile.ExtractToDirectory(zipFilePath, tempDirectoryPath);

Make Directory savehere to be virtual directory and give read/write permission from control panel


Had a directory by the same name as the file i was trying to write, so people can look out for that as well.


I encountered this problem while developing on my local workstation.

After several unsuccessful iisreset invocations, I remedied this situation by rebooting my machine.

In retrospect, an open file handle may have been causing issues.


In my case I had to add a .NET Authorization Rule for the web site in IIS.

I added a rule to allow anonymous users.

.NET 인증 규칙


I had the same problem but I fixed it by saving the file in a different location and then copying the file and pasting it in the location where I wanted it to be. I used the option to replace the the existing file and that did the trick for me. I know this is not the most efficient way but it works and takes less than 15 seconds.


I had a lot of trouble with this, specifically related to my code running locally but when I needed to run it on IIS it was throwing this error. I found that adding a check to my code and letting the application create the folder on the first run fixed the issue without having to mess with the folders authorizations.

something like this before you call your method that uses the folder

bool exists = System.IO.Directory.Exists("mypath");

        if (!exists)
            System.IO.Directory.CreateDirectory("mypath");

나는 완전한 권한을 가진 가상 디렉토리를 만들고 거기에 ffmpeg 소스 및 비디오 파일을 추가 했으므로 결국 누구나 사용할 수 있으므로 의미가 있습니다.

참고 URL : https://stackoverflow.com/questions/4877741/access-to-the-path-is-denied

반응형