我使用HttpRuntime.AppDomainAppPath
(例如此C:/personal/Website/page.aspx
)
Web服务始终位于父文件夹的page.aspx父级(如此C:/personal/Service/service.asmx
)。我在servicePath
变量中使用ABC.dll来获取webservice-path,就像这个字符串servicePath="C:/personal/Service/service.asmx"
一样。
如何根据网站路径检查服务路径?
If (GetWebPath()== GetServicePath())
{
// ... do something
}
private string GetWebPath()
{
string path = HttpRuntime.AppDomainAppPath;
string[] array = path.Split('\\');
string removeString = "";
for(int i = array.Length; --i >= 0; )
{
removeString = array[array.Length - 2];
break;
}
path = path.Replace(@"\" + removeString + @"\", "");
return path;
}
private string GetServicePath()
{
string path = @"C:\MNJ\OLK\ABC.asmx"
string[] array = path.Split('\\');
string removeString = "";
for(int i = array.Length; --i >= 0; )
{
removeString = @"\" + array[array.Length - 2] + @"\" + array[array.Length - 1];
path = path.Replace(removeString, "");
break;
}
return path;
}
答案 0 :(得分:1)
答案 1 :(得分:1)
如果您想检查以下内容:
string webPath = @"C:\blabla\CS_Web\website\";
string servicePath = @"C:\blabla\CS_Web\SPM\Server.asmx";
你应该致电
string webPathParentDir = GetParentDirectoryName(webPath);
string servicePathParentDir = GetParentDirectoryName(servicePath);
if (servicePathParentDir.Equals(webPathParentDir, StringComparison.OrdinalIgnoreCase))
{
// ... do something
}
方法:
private string GetParentDirectoryName(string path)
{
string pathDirectory = Path.GetDirectoryName(servicePath);
return new DirectoryInfo(pathDirectory).Parent.FullName;
}
答案 2 :(得分:1)
string webPath = @"C:\blabla\CS_Web\website\";
string servicePath = @"C:\blabla\CS_Web\SPM\Server.asmx";
if(Path.GetDirectory(Path.GetDirectoryName(servicePath))==Path.GetDirectoryName(webPath)
{
//You do something here
}
您必须使用Path.GetDirectoryName()
向上翻页到父文件夹