C#ASP目录不存在时为true';T
我在检查目录.Exists时遇到问题,当目录不存在时,它总是返回true。至少这些是我基于错误日志的假设 注意:问题不是发生在本地开发环境中,而是发生在生产环境中 因此,首先,以下是错误消息: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
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))这一行是如何被绕过的
我很困惑,希望有人能解释一下发生了什么。您正在尝试访问站点根文件夹之外的文件夹。
如果生产环境是“云”,那么您需要提供对目录的访问。
提供访问取决于您的云环境
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);
您正在尝试访问站点根文件夹之外的文件夹。
如果生产环境是“云”,那么您需要提供对目录的访问。
提供访问取决于您的云环境
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您是否尝试在另一台机器上运行该代码?它的行为方式是否相同?根据文档()代码看起来不错。您的应用程序是否有权限访问位于udnerd:\home\site\wwwroot\media\cdn的所有文件和目录?我有点搞不清楚这是如何编译的?除非您的类被称为目录
?@KennethK。问题是media\cdn
path不存在,这就是问题所在@Jamie Rees函数ExistsInFileSystem
在名为目录的类中
@JamieRees您是否尝试在另一台机器上运行该代码?它的行为方式是否相同?根据文档()代码看起来不错。