Access to the path is denied

2019-01-02 20:16发布

I know this question was asked many times here, but I can't find a solution to my problem. I'm trying to save image to the folder in .net c# but get this exception:

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)

I gave full control to this folder (savehere) to network service and iis_iusrs, even gave full control to everyone but still getting this exception. I tried to give access via explorer and via IIS manager, still no luck

I'm doing it on Windows server 2008 R2 and IIS 7.5, Who do I need to give access?

Thanks

19条回答
无与为乐者.
2楼-- · 2019-01-02 20:38

please add IIS_IUSERS full control permission to your folder. you find this option from security tab in folder properties. find this option and user in this image

查看更多
妖精总统
3楼-- · 2019-01-02 20:40

I Solved with this setting:

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

查看更多
长期被迫恋爱
4楼-- · 2019-01-02 20:46

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!

查看更多
余生请多指教
5楼-- · 2019-01-02 20:47

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.

查看更多
浪荡孟婆
6楼-- · 2019-01-02 20:48

I got this problem when I try to save the file without set the file name.

Old Code

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

Working Code

File.WriteAllBytes(@"E:\Folder\"+ fileName, Convert.FromBase64String(Base64String));
查看更多
皆成旧梦
7楼-- · 2019-01-02 20:48

I created a virtual dir with full permission and added the ffmpeg source and video files there, so finally it made sense as it can be acess by anyone.

查看更多
登录 后发表回答