Please visit my new Web Site https://coderstechzone.com
Few days ago i have a requirement that client wants to display category wise sites in his home page. To do that at first what i need? I need to display an external URL or website in my aspx page. After a short search i found an example on this by devasp. For your learning i want to share the code with you.
Add the panel into your aspx page :
Add the panel into your aspx page :
<asp:panel id="mainpanel" BorderStyle="Dotted" BorderColor="orange" BorderWidth="2"
style="POSITION: absolute;top:3px;left:3px" runat="server" Width="99%"></asp:panel>
style="POSITION: absolute;top:3px;left:3px" runat="server" Width="99%"></asp:panel>
protected void Page_Load(object sender, EventArgs e)
{
Uri weburi = new Uri(http://www.gmail.com/);
StringBuilder str = new StringBuilder();
string temp = "";
HttpWebRequest webrequest = (HttpWebRequest)WebRequest.Create(weburi);
HttpWebResponse webresponse = (HttpWebResponse)webrequest.GetResponse();
StreamReader webstream = new StreamReader(webresponse.GetResponseStream(), Encoding.ASCII);
while ((temp = webstream.ReadLine()) != null)
str.Append(temp + "\r\n");
webstream.Close();
mainpanel.Controls.Add(new System.Web.UI.LiteralControl(str.ToString()));
}
* Don't forget to add namespace: using System.Text;using System.Net;using System.IO; {
Uri weburi = new Uri(http://www.gmail.com/);
StringBuilder str = new StringBuilder();
string temp = "";
HttpWebRequest webrequest = (HttpWebRequest)WebRequest.Create(weburi);
HttpWebResponse webresponse = (HttpWebResponse)webrequest.GetResponse();
StreamReader webstream = new StreamReader(webresponse.GetResponseStream(), Encoding.ASCII);
while ((temp = webstream.ReadLine()) != null)
str.Append(temp + "\r\n");
webstream.Close();
mainpanel.Controls.Add(new System.Web.UI.LiteralControl(str.ToString()));
}
Output:
Common Error:
1. Invalid URI: The format of the URI could not be determined.
Solution: Supply full URL like http://www.gmail.com/ instead of http://www.gmail.com/
2 comments:
sir i want to talk to you.. is it possible... please replay me.. to.rohan@yahoo.com
error in Uri
weburi = new Uri(http://www.gmail.com/);
(invalid expression terms ':') after http:
help me please
I WOULD BE DELIGHTED TO HEAR FROM YOU