SimpleBrowserDotNet/SimpleBrowser

Browser not automatically redirecting for 301/302 responses when AutoRedirect is 'true'

MChartier opened this issue · 3 comments

I'm new to SimpleBrowser, but I'm having trouble getting started by following the provided examples because the Browser object does not appear to be automatically redirecting as expected.

var browser = new Browser();
browser.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.10 (KHTML, like Gecko) Chrome/8.0.552.224 Safari/534.10";
browser.AutoRedirect = true;
browser.Navigate("http://en.wikipedia.org");
if (browser.LastWebException != null)
{
     // This line is always hit
    return null;
}

Instead of automatically redirecting on a 301 or 302 response as configured, the LastWebException is populated with a WebException related to a 301 TLS Redirect. I would expect the Browser instance to automatically redirect to "https://en.wikipedia.org/wiki/Main_Page".

Bug or user error? If the latter, what should I be doing differently?

This is a bug, but it's already reported as Issue #198. SimpleBrowser is written using .NET Framework 4.0. .NET Framework 4.0 does not support TLS 1.2, which is what Wikipedia requires (and increasing number of well-maintained web sites require). Therefore, when the 301 or 302 redirect occurs and the browser is redirected from http to https, an exception occurs.

You have two options:

  1. Upgrade the SimpleBrowser project to .NET Framework 4.5. (Then submit that change as a pull request as a solution for Issue #198.)
  2. There is a line of code to add to the SimpleBrowser static constructor in Issue #198. Add that line of code, then recompile SimpleBrowser. (This is a bit of a hack, and requires that your project using SimpleBrowser is .NET Framework 4.5 or better.)

Thanks for the quick reply pointing me in the right direction.

I decided to do the .NET 4.5 upgrade today. I will be checking it in shortly.