This tutorial will show you how to retrieve an external webpage using the .NET System.Net class, ASP.NET 2.0 and C#.NET

The .NET Framework offers a number of types that makes accessing resources on the network easy.

To display an external webpage we will need to use the System.IO, System.Net, and System.Text namespaces.

We’ll put our code in the Page_Load() event.

When the Page_Load() event fires it instantiates a new WebRequest object with the URL that we wish to retrieve. We then execute the GetResponse() method of this new object which returns a WebResponse object. After this is complete it is simply a matter of executing the GetResponseStream() method of the WebResponse object and reading the stream that is returned.

The front end .aspx page looks something like this:

The flow for the code behind page is as follows:

Download Source Files