访问路径被拒绝asp.net IIS

访问路径被拒绝asp.net IIS

问题描述:

我要保存文件上传文件在 'C:\的Inetpub \ wwwroot的\内容\ SpeechFile \' 在Visual Studio中我可以保存此文件访问路径被拒绝asp.net IIS

if (file != null) 
      { 
       string urlfile; 
       string path = Server.MapPath("~" + "\\Content\\Apk\\"); 
       string filename = System.IO.Path.GetFileName(file.FileName); 
       while (System.IO.File.Exists(path + "\\" + filename)) 
        filename = "1" + filename; 
       urlfile = "../../Content/Apk/" + filename; 
       file.SaveAs(path + filename); 
       model.Fileurl = urlfile; 
      } 

但在服务器上我有一个错误

访问路径'C:\ inetpub \ wwwroot \ Content \ SpeechFile \ nokia 700.jpg'被拒绝。

+2

如果您新创建了文件夹“SpeechFile”,那么请检查它的访问权限。 – watraplion

+1

[ASP.net可能的重复获取错误“访问路径被拒绝”。而试图上传文件到我的Windows Server 2008 R2 Web服务器](http://stackoverflow.com/questions/19724297/asp-net-getting-the-error-access-to-the-path-is-denied-while -trying到上传) –

出于安全原因,通常应用程序池下运行的用户帐户将无权写入任何子文件夹。您必须检查您的应用程序在哪个用户下运行,然后授予该用户对SpeechFile文件夹的写入权限。确保这是您授予写入权限的唯一文件夹,以便将安全风险降至最低。

解决此问题的唯一方法是不写入该文件夹。您无权写入该文件夹。只是试图将Access Rights添加到您的文件夹SpeechFile

您也可以使用Environment.SpecialFolder来帮助您找到需要去的地方。