【问题标题】:In ASP.net I am getting error Access to the path '~\Upload\1_myimage.png' is denied?在 ASP.net 中,我收到错误访问路径“~\Upload\1_myimage.png”被拒绝?
【发布时间】:2016-10-26 09:58:53
【问题描述】:

当我尝试将图像保存在名为 Upload 的上传文件夹中时,我已将我的网站上传到服务器上,然后它给出了错误

第 114 行:{ 第 115 行:字符串 str = imagepath;
第 116 行:fuStudentPhoto.PostedFile.SaveAs(Server.MapPath("~/Upload/" +str)); 第 117 行:图像 = str;

我授予了上传文件夹的所有权限,但它仍然停留在此处。帮我解决这个问题...

【问题讨论】:

  • 获得权限后是否构建解决方案
  • 还有 om imagepath 你需要 pul 文件名
  • 不不...会这样做...并让您知道...谢谢:)
  • 也给出图像名称而不是图像路径
  • 它不工作,你能用小例子解释一下吗:)

标签: asp.net asp.net-web-api


【解决方案1】:

为用户 IIS_IUSRS 授予服务器上“上传”目录的完全权限。

【讨论】:

    【解决方案2】:

    在你的行动中 [HttpPost] 您的输入将是 HttpPostedFileBase file 并且您输入的文件类型应该具有 name="file" 然后:

    <input type="file" name="file" id="file" />
    

    在您的 .net 控制器中

    var filename = Sytem.IO.Path.GetFileName(file.FileName);
    
    file.SaveAs(Server.MapPath(Path.Combine("~/Upload/", filename)));
    

    不要忘记将 enctype="multipart/form-data" 放入表单中

    【讨论】:

      【解决方案3】:

      第 114 行:{ 第 115 行:字符串 str = imagepath;第 116 行:fuStudentPhoto.PostedFile.SaveAs(Server.MapPath("~/Upload/" +str)); 第 117 行:图像 = str;

      上述方法无效,您必须将其替换为

      filename = Path.GetFileName(file_upload.PostedFile.FileName);
      file_upload.PostedFile.SaveAs(Server.MapPath(SaveLocation + "\\" + filename));
      

      记得在 SaveAs 方法中也指定文件名。

      信用:ASP.net Getting the error "Access to the path is denied." while trying to upload files to my Windows Server 2008 R2 Web server

      【讨论】:

      • 会尽力让你知道:)
      • @SurajBinorkar 好的
      • @suraraj Binokar 然后接受答案并关闭问题。
      猜你喜欢
      • 1970-01-01
      • 2013-12-15
      • 1970-01-01
      • 1970-01-01
      • 2011-12-04
      • 1970-01-01
      • 1970-01-01
      • 2016-11-11
      相关资源
      最近更新 更多