How to load another webpage in ASP.NET

I want to load some fixed part from another website into my web application. How to do it? Thank.

+5
source share
2 answers

You can do this in several ways:

  • On the client side, upload the content to <iframe>
  • On the client side, download the content with ajaxand write it to the page.
  • On the server side, load the page with WebClient DownloadStringand write it to your page.

Update

After you get your string, you can analyze it and grab the right material using the Html Agility Pack . (Also available on Nuget)

+6

WebRequest :

string url = "http://somesite.com/somepage.php";
WebRequest request = WebRequest.Create(url);
WebResponse response = request.GetResponse();
using (StreamReader reader = new StreamReader(response.GetResponseStream()))
{
    string contents = reader.ReadToEnd();
    //parse contents as you wish.......
    reader.Close();
}
response.Close();
+5

All Articles