我试图保存一个图像到。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)

我完全控制了这个文件夹(savehere)到网络服务和iis_iusrs,甚至完全控制了每个人,但仍然得到这个异常。 我尝试通过浏览器和IIS管理器访问,仍然没有运气

我是在Windows server 2008 R2和IIS 7.5上做的,我需要给谁访问权限?


当前回答

也许对你有帮助。

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

其他回答

我也有同样的问题。

解决方案是我试图访问的文件是只读的,因为它是从只读的模板文件复制的。

< facepalm - >

在我的例子中,我试图访问一个设置为只读的文件

我通过禁用只读来解决它,我得到了它的修复!

希望它能对像我一样经历这种情况的人有所帮助。

请将IIS_IUSERS完全控制权限添加到您的文件夹。 您可以在文件夹属性中的安全选项卡中找到此选项。

我解决了这个设置:

IIS >应用程序池>[您的站点]>高级设置…> 标识>内置帐户> LocalSystem

有一个与我试图写的文件同名的目录,所以人们也可以找到它。