Access to the path is denied
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:inetpubwwwrootmysiteimagessavehere' 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
您需要从应用程序池中找到该网站的运行身份(默认情况下为Application Pool Identity
),并授予该权限。
Access to the path 'C:inetpubwwwrootmysiteimagessavehere' is denied
Read the message carefully. You are trying to save to a file that has the same name as the directory. That cannot work, you can't overwrite a directory filled with files with a single new file. That would cause undiagnosable data loss, "Access to the path is denied" is the file system fighting back to prevent that from happening.
The exception message is not ideal, but it comes straight from the OS and they are cast in stone. The framework often adds extra checks to generate better messages, but this is an expensive test on a network. Perf is a feature too.
You need to use a name like 'C:inetpubwwwrootmysiteimagessaveheremumble.jpg'. Consider Path.Combine() to reliably generate the path name.
I was having the same problem while trying to create a file on the server (actually a file that is a copy from a template).
Here's the complete error message:
{ERROR} 08/07/2012 22:15:58 - System.UnauthorizedAccessException: Access to the path 'C:inetpubwwwrootSAvETemplatesCover.pdf' is denied.
I added a new folder called Templates
inside the IIS app folder. One very important thing in my case is that I needed to give the Write (Gravar) permission for the IUSR user on that folder. You may also need to give Network Service
and ASP.NET v$.#
the same Write permission.
After doing this everything works as expected.
链接地址: http://www.djcxy.com/p/36080.html上一篇: 连接到网络共享时如何提供用户名和密码
下一篇: 访问路径被拒绝