Advertisement
Guest User

Untitled

a guest
Apr 24th, 2014
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. Uri baseUri = new Uri(url); //main URL
  2. Uri myUri = new Uri(baseUri, strRef); //strRef is new found link
  3. //domain = baseUri.Host;
  4. domain = baseUri.Host.Replace("www.", string.Empty).Replace("http://", string.Empty).Replace("https://", string.Empty).Trim();
  5.  
  6. string domain2=myUri.Host.Replace("www.", string.Empty).Replace("http://", string.Empty).Replace("https://", string.Empty).Trim();
  7.  
  8. strRef = myUri.ToString();
  9. if (domain2==(domain) )
  10. { //DO STUFF }
  11.  
  12. string url = "http://www.xxx.co.uk";
  13. string strRef = "http://www.news.xxx.co.uk";
  14.  
  15. Uri baseUri = new Uri(url); //main URL
  16. Uri myUri = new Uri(baseUri, strRef); //strRef is new found link
  17. var domain = baseUri.Host;
  18. domain = baseUri.Host.Replace("www.", string.Empty).Replace("http://", string.Empty).Replace("https://", string.Empty).Trim();
  19.  
  20. //hrere is solution
  21.  
  22. string domain2 = GetDomainName(strRef);
  23.  
  24. strRef = myUri.ToString();
  25. if (domain2 == (domain))
  26. { //DO STUFF
  27.  
  28. }
  29.  
  30.  
  31.  
  32. private static string GetDomainName(string url)
  33. {
  34. string domain = new Uri(url).DnsSafeHost.ToLower();
  35. var tokens = domain.Split('.');
  36. if (tokens.Length > 2)
  37. {
  38. //Add only second level exceptions to the < 3 rule here
  39. string[] exceptions = { "info", "firm", "name", "com", "biz", "gen", "ltd", "web", "net", "pro", "org" };
  40. var validTokens = 2 + ((tokens[tokens.Length - 2].Length < 3 || exceptions.Contains(tokens[tokens.Length - 2])) ? 1 : 0);
  41. domain = string.Join(".", tokens, tokens.Length - validTokens, validTokens);
  42. }
  43. return domain;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement