Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/311.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#ASP目录不存在时为true';T_C#_Asp.net_Kentico - Fatal编程技术网

C#ASP目录不存在时为true';T

C#ASP目录不存在时为true';T,c#,asp.net,kentico,C#,Asp.net,Kentico,我在检查目录.Exists时遇到问题,当目录不存在时,它总是返回true。至少这些是我基于错误日志的假设 注意:问题不是发生在本地开发环境中,而是发生在生产环境中 因此,首先,以下是错误消息: Message: Could not find a part of the path 'd:\home\site\wwwroot\media\cdn'. Exception type: System.IO.DirectoryNotFoundException Stack Trace: at Syste

我在检查目录.Exists时遇到问题,当目录不存在时,它总是返回true。至少这些是我基于错误日志的假设

注意:问题不是发生在本地开发环境中,而是发生在生产环境中

因此,首先,以下是错误消息:

Message: Could not find a part of the path 'd:\home\site\wwwroot\media\cdn'.

Exception type: System.IO.DirectoryNotFoundException
Stack Trace: 
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileSystemEnumerableIterator`1.CommonInit()
at System.IO.FileSystemEnumerableIterator`1..ctor(String path, String originalUserPath, String searchPattern, SearchOption searchOption, SearchResultHandler`1 resultHandler, Boolean checkHost)
at System.IO.Directory.GetFiles(String path, String searchPattern)
at CMS.AzureStorage.Directory.GetFiles(String path, String searchPattern)
at CMS.IO.Directory.GetFiles(String path, String searchPattern)
at CMS.AzureStorage.DirectoryInfo.GetFiles(String searchPattern, SearchOption searchOption)
相关功能(精简为相关代码):

public override string[]GetFiles(字符串路径,字符串搜索模式)
{
List stringList=新列表();
if(Directory.ExistsInFileSystem(path))
{
foreach(System.IO.Directory.GetFiles(路径、搜索模式)中的字符串文件)
Add(Directory.GetCaseValidPath(文件,newbool?());
}
...
}
公共静态bool ExistsInFileSystem(字符串路径)
{
返回System.IO.Directory.Exists(路径);
}
正如您所看到的,它正在进入
System.IO.Directory.GetFiles
,但我不明白的是,当目录不存在时,if(Directory.ExistsInFileSystem(path))这一行是如何被绕过的


我很困惑,希望有人能解释一下发生了什么。

您正在尝试访问站点根文件夹之外的文件夹。
如果生产环境是“云”,那么您需要提供对目录的访问。
提供访问取决于您的云环境

  • 如果您正在使用VM,则可以直接转到IIS并提供目录访问
  • 对于其他型号,您需要通过代码提供访问权限
  • 下面是提供对wwwroot文件夹的读写访问权限的代码。 您可以在下面的代码之后调用您的代码

    string file = @"d:\home\site\wwwroot"; 
    DirectoryInfo dInfo = new DirectoryInfo(file);
    DirectorySecurity dSecurity = dInfo.GetAccessControl();
    dSecurity.AddAccessRule(new FileSystemAccessRule(new SecurityIdentifier(WellKnownSidType.WorldSid, null), FileSystemRights.FullControl, InheritanceFlags.ObjectInherit | InheritanceFlags.ContainerInherit, PropagationFlags.NoPropagateInherit, AccessControlType.Allow));
    dInfo.SetAccessControl(dSecurity);
    

    您正在尝试访问站点根文件夹之外的文件夹。
    如果生产环境是“云”,那么您需要提供对目录的访问。
    提供访问取决于您的云环境

  • 如果您正在使用VM,则可以直接转到IIS并提供目录访问
  • 对于其他型号,您需要通过代码提供访问权限
  • 下面是提供对wwwroot文件夹的读写访问权限的代码。 您可以在下面的代码之后调用您的代码

    string file = @"d:\home\site\wwwroot"; 
    DirectoryInfo dInfo = new DirectoryInfo(file);
    DirectorySecurity dSecurity = dInfo.GetAccessControl();
    dSecurity.AddAccessRule(new FileSystemAccessRule(new SecurityIdentifier(WellKnownSidType.WorldSid, null), FileSystemRights.FullControl, InheritanceFlags.ObjectInherit | InheritanceFlags.ContainerInherit, PropagationFlags.NoPropagateInherit, AccessControlType.Allow));
    dInfo.SetAccessControl(dSecurity);
    

    您的应用程序是否有权限访问位于udner
    d:\home\site\wwwroot\media\cdn的所有文件和目录?我有点搞不清楚这是如何编译的?除非您的类被称为
    目录
    ?@KennethK。问题是
    media\cdn
    path不存在,这就是问题所在@Jamie Rees函数
    ExistsInFileSystem
    在名为
    目录的类中
    @JamieRees您是否尝试在另一台机器上运行该代码?它的行为方式是否相同?根据文档()代码看起来不错。您的应用程序是否有权限访问位于udner
    d:\home\site\wwwroot\media\cdn的所有文件和目录?我有点搞不清楚这是如何编译的?除非您的类被称为
    目录
    ?@KennethK。问题是
    media\cdn
    path不存在,这就是问题所在@Jamie Rees函数
    ExistsInFileSystem
    在名为
    目录的类中
    @JamieRees您是否尝试在另一台机器上运行该代码?它的行为方式是否相同?根据文档()代码看起来不错。