4

私は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;
    }
4

3 に答える 3

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()を使用してページを親フォルダーにアップする必要があります

于 2013-03-18T12:10:18.780 に答える
1

これを試して:

System.Web.Server.MapPath(webPath);

これにより、現在実行中のWebファイルの物理ファイルパスが返されます。

詳細については、 System.Web.Serverを参照してください。

于 2013-03-13T08:24:16.733 に答える
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;
}
于 2013-03-13T09:51:12.633 に答える