I have get my website path using HttpRuntime.AppDomainAppPath
(like this C:/personal/Website/page.aspx
)
Web service is always located on page.aspx parent of parent folder (like this C:/personal/Service/service.asmx
). I get the webservice-path using a ABC.dll in servicePath
variable like this string servicePath="C:/personal/Service/service.asmx"
.
How to check service path against website path?
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;
}
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
}
You have to up page to parent folder using Path.GetDirectoryName()