日期:2014-05-18  浏览次数:20490 次

asp.net拒绝访问啊~
下面这个是用于修改头像 上传新头像 然后 删除原来旧头像  
其中判断要删除的头像是不是系统默认的头像 
如果是系统的默认头像则不删除  

合租的服务器文件夹权限已经分配 本人怀疑是代码的问题  

这段代码放到合租的服务器虚拟目录上面 老是提示拒绝访问  
“路径“D:\hosting\wwwroot\web\htdoc\touxiangimage\20122523060618711.jpg”的访问被拒绝。”
public int UpHead(string filename, FileUpload fu, string sessionname)
  {
  int mes_key = 0;
  string fileleixing;
  fileleixing = System.IO.Path.GetExtension(filename).ToString();
  if (fu.PostedFile.ContentLength > 204800)
  {
  mes_key = 2;


  }
   

  Random rmd = new Random();
  string filepath = null;
  filepath = System.DateTime.Now.ToString() + rmd.Next(1, 65535);
  filepath = filepath.Replace(":", "").Replace(" ", "").Replace("-", "") + fileleixing; //生成文件名
  fu.SaveAs(System.Web.HttpContext.Current.Server.MapPath("/touxiangimage/"+filepath)); //上传文件到指定的目录,上传文件成功



  if (System.IO.File.Exists(System.Web.HttpContext.Current.Server.MapPath("/touxiangimage/"+filepath)))
  {
  string uploadurl = filepath; //获取新头像的web路径
  UserDataClassesDataContext d = new UserDataClassesDataContext();
  UserOr mor = d.UserOrs.Single(uor => uor.username == sessionname.ToString());
  if (mor.userhead != "moren.jpg") //用于判断是否是系统的默认头像 如果不是则删除该图片
  {
  System.IO.FileInfo file = new System.IO.FileInfo(System.Web.HttpContext.Current.Server.MapPath("/touxiangimage/" + filepath));
  file.Delete(); //先删除原来的头像文件
  }
  mor.userhead = uploadurl; //再将新的文件url插入数据库
  try
  {
  d.SubmitChanges();
  mes_key = 1;
  }
  catch (Exception ex)
  {
  mes_key = -1;
  }
  }
  else
  {
  mes_key = -1;
  }
   
  return mes_key;
  }

------解决方案--------------------
你在你本机建一个同样的目录测试一下就OK了 如果本机通过则是服务器的问题 如果本机通不过则是你代码路径的问题
------解决方案--------------------
是因为登录网站一般采用的是匿名用户(在IIS那里有设),这个用户是没有删除文件的权限的。


------解决方案--------------------
给Asp.net账户赋予文件夹的读、写权限......