拒绝访问该路径

时间:2016-07-09 09:34:52

标签: c# asp.net-mvc file-upload hosting file-permissions

我已编写代码在.net MVC Web应用程序中上传excel文件。 它在本地主机上工作正常,因为没有在win主机服务器上工作它的捕获错误访问拒绝的路径。我已经授予权限并在filezilla文件夹列表中添加完全控制。但仍显示错误:拒绝访问路径。有什么东西我错过了我需要授权的地方。

我的代码如下:

  String laborpath="~/ExcelUploads/Labor_Excel/";
  String filename=Request.Files["FileUpload1"].FileName
  string filePath= string.Format(Server.MapPath(laborpath)+ filename); 
  foreach (string inputTagName in Request.Files)
  {
   HttpPostedFileBase Infile = Request.Files[inputTagName];
   Infile.SaveAs(filePath);
  }

2 个答案:

答案 0 :(得分:0)

右键单击服务器或本地计算机上的文件夹,并授予

完全权限

IIS_IUSRS

https://stackoverflow.com/a/21498502/2745294

答案 1 :(得分:0)

我找到了解决方案,我只是将目标目录移动到App_data文件夹,它为我工作。有一个参考链接:

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