求教上传权限问题
我写的一个网站放到国内,或者香港空间上传都没有问题。因为客户是针对海外市场的所以放到美国空间,但是放到美国空间之后上传就报异常,导致上传不成功!
错误异常:
我写的代码:
string imgpath = ""; Random ran = new Random(); if (FileUpload1.HasFile) { string fileContentType = FileUpload1.PostedFile.ContentType; if (fileContentType == "image/bmp" || fileContentType == "image/gif" || fileContentType == "image/pjpeg") { string name = FileUpload1.PostedFile.FileName; // 客户端文件路径 DateTime time = DateTime.Now; string newfilename = time.Year.ToString() + time.Month + time.Day + time.Hour.ToString() + time.Millisecond.ToString() + ran.Next(1000, 9999).ToString() + time.Second.ToString() + time.Millisecond.ToString() + ran.Next(1000, 9999).ToString(); FileInfo file = new FileInfo(name); string fileName = file.Name; // 文件名称 string extension = Path.GetExtension(file.Extension); fileName = newfilename + extension; imgpath = "uploadfile/" + fileName; string webFilePath = Server.MapPath("../uploadfile/" + fileName); // 服务器端文件路径 if (!File.Exists(webFilePath)) { try { FileUpload1.SaveAs(webFilePath); // 使用 } catch (Exception ex) { Alert.ShowOnly("Tip: file upload fails, the reason for failure:" + ex.Message); } } else { Alert.ShowOnly("Tip: file already exists. Please rename after uploading"); } } else { Alert.ShowOnly("Tip: file types"); } this.SmallPic.Value = imgpath; }