Check if 2 URLs are equal

后端 未结 6 1530
囚心锁ツ
囚心锁ツ 2020-12-15 06:10

Is there a method around that tests if 2 URLs are equal, ie point to the same place. I am not talking about 2 URLs with different domain names pointing to the same IP addres

6条回答
  •  旧巷少年郎
    2020-12-15 06:57

    Maybe this tutorial can be of help to you?

    "...You want to see how to handle identical Urls in the sitemap (which is forbidden by the out-of-the-box SiteMapProvider)..."

    /// 
    /// SiteMap datasources cannot have duplicate Urls with the default provider.
    /// This finds duplicate urls in your heirarchy and tricks the provider into treating
    /// them correctly
    /// 
    private void modifyDuplicateUrls()
    {
    StringCollection urls = new StringCollection();
    string rowUrl = String.Empty;
    uint duplicateCounter = 0;
    string urlModifier = String.Empty;
    foreach (DataTable dt in this.DataSource.Tables)
    {
    foreach (DataRow dr in dt.Rows)
    {
    rowUrl = (string)dr["Url"];
    if (urls.Contains(rowUrl))
    {
    duplicateCounter++;
    if (rowUrl.Contains("?"))
    {
    urlModifier = "&instance=" + duplicateCounter.ToString();
    }
    else
    {
    urlModifier = "?instance=" + duplicateCounter.ToString();
    }
    dr["Url"] = rowUrl + urlModifier;
    }
    else
    {
    urls.Add(rowUrl);
    }
    }
    }
    }
    }
    

提交回复
热议问题