繁体   English   中英

访问路径 'c:\windows\system32\inetsrv\config\' 被拒绝

[英]Access to the path 'c:\windows\system32\inetsrv\config\' is denied

if (Fubrowse.HasFile)
{
  string path = Path.GetFullPath(Fubrowse.PostedFile.FileName);
  //string root = Path.GetPathRoot(path);
  GetFilesFromDirectory(path.Substring(0, path.LastIndexOf("\\")));
}
else
  GeneralClass.ShowMessageBox("Please Select File First.");
}

private void GetFilesFromDirectory(string DirPath)
{
  try
  { 
    DirectoryInfo Dir = new DirectoryInfo(DirPath);
    FileInfo[] FileList = Dir.GetFiles("*.cs", SearchOption.AllDirectories);
    foreach (FileInfo FI in FileList)

在这里,路径是c:\windows\system32\inetsrv\config\ 我想在FileList数组中获取所有子目录的文件名。

运行您的代码的 Windows 帐户需要对该文件夹的读取权限(通常需要管理员权限)。

  • 如果你从 Visual Studio 运行程序,那是你的帐户。 以管理员身份运行 VS,您的代码应该可以正常工作。
  • 如果它是 Web 应用程序,则应用程序池帐户需要对该文件夹具有读取权限。
  • 如果它是 Windows 服务,则主机帐户需要访问权限。

我遇到过同样的问题。 我无法从C:\Windows\system32\intesrv\config获取文件,因为我的系统是 64 位,并且我的请求重定向到C:\Windows\SysWOW64\system32\intesrv\config这个答案给出了更多解释。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM