从服务器中下文件,使用的方式是在WebServer中使用FileStream流来读写文件, 但是读到IIS的虚拟目录中的文件就会报出的错是"访问被拒绝", 是权限的原因还是其他原因?有人知道怎么解决吗?

解决方案 »

  1.   

    在文件修改权限中添加ASPNET用户为完全控制
      

  2.   

    对文件所存的目录具有可写权限即可不过你还要注意一个问题,参看
    http://blog.csdn.net/knight94/archive/2006/03/31/646252.aspx
      

  3.   

    我从其他路径中读写文件都没问题, 惟独IIS目录, 可昨天晚上又试了下.能往IIS里写文件,就是读文件的时候报错.
      

  4.   

    FileStream fs = new FileStream(Server.MapPath(".") + @"\aaa.txt", FileMode.Open);
    程序运行到这段代码就报错走不过去, 这段代码写在WebService中,我用WinForm调用.
      

  5.   

    {"System.Web.Services.Protocols.SoapException: 服务器无法处理请求。 ---> System.UnauthorizedAccessException: 对路径“c:\\inetpub\\wwwroot\\WebSite\\aaa.txt”的访问被拒绝。\n   在 System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)\n   在 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)\n   在 System.IO.FileStream..ctor(String path, FileMode mode)\n   在 Service.bt()\n   --- 内部异常堆栈跟踪的结尾 ---"} System.Exception {System.Web.Services.Protocols.SoapException}
    这是程序报的错.
      

  6.   

    to FileStream fs = new FileStream(Server.MapPath(".") + @"\aaa.txt", FileMode.Open);你看看Server.MapPath(".")获得是什么
      

  7.   

    得到的是webservice程序的目录路径"c:\inetpub\wwwroot\WebSite"
      

  8.   

    下面的代码是webservice里读文件的函数接口.
    [WebMethod]
        public byte[] bt()
        {
            byte[] bt = null;
            FileStream fs = new FileStream(Server.MapPath(".") + @"\aaa.txt",FileMode.Open);
            //FileStream fs = new FileStream(@"d:\test.txt", FileMode.Open);
            bt = new byte[fs.Length];
            fs.Read(bt, 0, bt.Length);
            fs.Close(); 
            return bt;
        }
      

  9.   

    change
    FileStream fs = new FileStream(Server.MapPath(".") + @"\aaa.txt",FileMode.Open);with
    FileStream fs = new FileStream(Server.MapPath(".") + @"\aaa.txt",FileMode.Open,
    FileAccess.Read);
      

  10.   

    你最好查看一下aspnet用户是否对此目录具有访问权限。
      

  11.   

    在家的机子上通过了,用
    FileStream fs = new FileStream(Server.MapPath(".") + @"\aaa.txt",FileMode.Open,
    FileAccess.Read);
    替换了原来的
    FileStream fs = new FileStream(Server.MapPath(".") + @"\aaa.txt",FileMode.Open);FileAccess.Read 这个参数是什么意思? 是准确的告诉系统本次操作只是对文件的读取吗?
      

  12.   

    刚试着把FileAccess.Read 改成 FileAccess.Write和FileAccess.ReadWrite 就报出权限的错误, 由此可以得出,第二个参数为FileMode.Open时,不具备写入的权限, 
    可为什么上传时就不会报出权限的问题呢? 我上传的代码是
     [WebMethod]
        public void upload(byte[] bt)
        {
            MemoryStream m = new MemoryStream(bt);
            FileStream fs = new FileStream(Server.MapPath(".") + @"\test.txt", FileMode.Create);
            m.WriteTo(fs);
            m.Close();
            fs.Close(); 
        }
    这段代码却能正常的通过,为什么?