Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
Read a Remote WEB Page in ASP.NET C#
WhatsApp
Rahul Kumar Saxena
9y
15.1
k
0
1
25
Blog
ReadRemoteWebPage.zip
Below is my aspx:
<%@ Page Language=
"C#"
AutoEventWireup=
"true"
CodeFile=
"Default.aspx.cs"
Inherits=
"_Default"
%>
<!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
>
<html xmlns=
"http://www.w3.org/1999/xhtml"
>
<head runat=
"server"
>
<title></title>
</head>
<body>
<form id=
"form1"
runat=
"server"
>
<div>
<asp:Label ID=
"lblResponse"
runat=
"server"
></asp:Label></div>
</form>
</body>
</html>
Now my aspx.cs is:
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Web;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
System.Net;
using
System.IO;
public
partial
class
_Default : System.Web.UI.Page
{
protected
void
Page_Load(
object
sender, EventArgs e)
{
string
URLResponse = GetHtmlPage(
"http://www.google.com"
);
lblResponse.Text = URLResponse;
}
static
string
GetHtmlPage(
string
strURL)
{
String strResult;
WebResponse objResponse;
WebRequest objRequest = HttpWebRequest.Create(strURL);
objResponse = objRequest.GetResponse();
using
(StreamReader sr =
new
StreamReader(objResponse.GetResponseStream()))
{
strResult = sr.ReadToEnd();
sr.Close();
}
return
strResult;
}
}
Here I am reading
http://www.google.com
and showing response in a label:
Image 1.
Up Next
How to Set Default Page Using Web.Config in ASP.NET
Ebook Download
View all
ASP.NET MVC 5: A Beginner’s Guide
Read by 28.1k people
Download Now!
Learn
View all
Membership not found