我试图保存一个图像到。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上做的,我需要给谁访问权限?


当前回答

使Directory savehere为虚拟目录,并从控制面板给予读/写权限

其他回答

确保你的目标在System.IO中。Delete(string file)是一个已经存在的文件。 也许你的代码中有错误,比如你没有将正确的文件名传递给方法,或者你的目标是一个文件夹。在这些情况下,你会看到:"access to the path is denied错误"。

当我试图在服务器上创建一个文件(实际上是从模板复制的文件)时,也遇到了同样的问题。

下面是完整的错误信息:

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

我在IIS应用程序文件夹中添加了一个名为Templates的新文件夹。在我的案例中,一个非常重要的事情是,我需要给IUSR用户在该文件夹上的写(Gravar)权限。您可能还需要提供网络服务和ASP。净v $。#相同的写权限。

完成此操作后,一切正常工作。

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

使Directory savehere为虚拟目录,并从控制面板给予读/写权限

我的问题是,我必须要求只读访问:

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