I have the following code. I’m doing some work on websites, but sometimes they redirect, and if they do so I want to do the work on the redirected site. BUT I don’t want to check all the sites for redirection before doing the work, as there are few of them. So how can I insert it in the loop? I know that I can’t insert into string array, but what’s the best structure? Probably list, because of insert, although I’m not so keen to hold on to the values, which we have already processed. I’m not proficient in C#.
string[] lines = System.IO.File.ReadAllLines(@"my_file_with_urls.txt");
foreach (string line in lines)
{
Uri default_uri = new Uri(line);
Uri response;
WebSiteIsAvailable(default_uri, out response);
//Do work on the actual link
if (!response.Host.Equals(default_uri.Host)){
//I want to run the work on the redirected website
}
}
1 Answer