我用asp.net 写了个文件上传的小东西
在本机.NET调试模式下,可以上传,没有问题
在本机IIS下上传,也没有问题
就是在其他机器上访问我IIS里的网站,上传就有问题了
老是提示上传失败。这里有什么需要设置的么?FileUpload fu = new FileUpload();
        HttpFileCollection hfc = Request.Files;
        HttpPostedFile hpf = hfc[0];
        string phpath = Server.MapPath("~/Upload/");
        string webpath = Request.ApplicationPath.ToString();
        string fileName = hpf.FileName;
        string ftype = hpf.ContentType;
        string imgpath = "../Upload/" ;
        if (ftype == "image/bmp" || ftype == "image/gif" || ftype == "image/jpeg" || ftype == "image/jpg")
        {
            this.LblError.Visible = false;
            if (this.TxtNewName.Text != "")
            {
                hpf.SaveAs(phpath + this.TxtNewName.Text + "." + ftype.Substring(6));
                fileName = this.TxtNewName.Text + "." + ftype.Substring(6);
            }
            else
            {
                string tiname=DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString() + "." + ftype.Substring(6, 3);
                hpf.SaveAs(phpath + tiname);
                fileName = tiname;
            }
            imgpath = imgpath + fileName;
            this.TextContent.Value = TextContent.Value + "<img src = " + imgpath + "></img>";
            this.TxtNewName.Text = "";
        }
        else
        {
            this.LblError.Text = "请选择图片上传!";
            this.LblError.Visible = true;
        }

解决方案 »

  1.   

    设置Upload目录的权限为IIS登录用户具有读写权限。
      

  2.   

    IIS目录如下:
    Internet 信息服务
    |--ZDKJ-KF(本地计算机)
      |--应用程序池
      |--网站
        |--默认网站
        |--UploadTest
          |--App_Code
          |--Upload
          |--Bin
      |--Web 服务扩展UploadTest是我上传的东西
    Upload是上传目录
    我这样设置的:
    UploadTest->属性->主目录(设置读取、写入)->目录安全性->身份验证和访问控制->编辑->启用匿名访问(打勾)
    ->浏览->ASPNET(用户)添加->取消“集成Window身份验证”
    Upload目录:
    Upload->属性->目录->(读取、写入)->
    目录安全性->身份验证和访问控制->编辑->启用匿名访问(打勾)->浏览->ASPNET(用户)添加
    ->取消“集成Window身份验证”我还把我硬盘的物理路径下的Upload目录设置了Everyone和ASP.NET计算机用户的完全控制权限最后郁闷了,还是传不了。。
    是不是我哪里还是设置不对?
      

  3.   

    问题找到了。
    是文件扩展名的问题
    string ftype = hpf.ContentType;
    这个东西在本地得到的是image/gif
    而在远程得到的却是application/octet-stream
    呵呵,改掉这个之后,就没有问题了,谢谢各位的热心