Hello i am building something like a webspider in C#. In my research i came across a problem were i need to determen if a link is internal or external, inbound or outbound. So i needed to create a function to do the work for me. So i came up with the following function but i am not sure if its the best possible algorythm in order to accomplish that task. So i would like your opinions upon this problem.
I asume that links with no http:// or https:// in front of the link are internal and if i have a domain http://www.blahblah.com then a link like test should still be internal despite the fact that it has http:// in front, but a link like http://www.somethingelse.com/?var1=http://www.blahblah.com/test is external sto i am checking the first letters only.
private Boolean checklinkifinternal(String link)
{
Boolean isinternal = false;
if (link.IndexOf("http://") == 0 || link.IndexOf("https://") == 0)
{
//Then probably external
if (link.IndexOf("http://" + UrlName) == 0 || link.IndexOf("https://" + UrlName) == 0 || link.IndexOf("http://www." + UrlName) == 0 || link.IndexOf("https://www." + UrlName) == 0)
{
isinternal = true;
}
}
else
{
isinternal = true;
}
return isinternal;
}
Uri.Compare(new Uri("google.de"), new Uri("Google.de"), UriComponents.Host, UriFormat.SafeUnescaped, StringComparison.CurrentCulture);
this is what i would say from the top of my head :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With