Hi,
I need to retrieve the HTML string of one of my ASP pages, and whenever I make the attempt using my code, it brings the entire server to a hault for quite a while. The server's hardware specs are perfectly fine, and I've narrowed it down to the Server.Execute line. Is there anything I can do here? Here's my code:
StringWriter sw =new StringWriter();Server.Execute("page.aspx", sw);String strHtmlCode = sw.GetStringBuilder().ToString();
Thanks!
Use HttpWebRequest/HttpWebResponse:
//using System.Net;
//using System.IO;
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;
}
String strHtmlCode = GetHtmlPage("http://domain/page.aspx");
This may be because page.aspx may be huge page and it will take long time in processing. Because of this, your current page execution will stop:)
Cheers
Bhavesh
lad.bhavesh:
This may be because page.aspx maybe huge page and it will take long time in processing. Because of this,your current page execution will stop:)
Cheers
Bhavesh
Including the one image and stylesheet, it's about 55 KB.
Mikesdotnetting:
Use HttpWebRequest/HttpWebResponse:
//using System.Net;
//using System.IO;
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;
}String strHtmlCode = GetHtmlPage("http://domain/page.aspx");
I apologize - I should have been more clear on the context here. A session needs to be maintained in order to access this page. Is there anything else I can use? And believe me, I've tried googling :). I'm sure it's out there somewhere, but I can't seem to find it.
Will this do you?
http://msdn2.microsoft.com/en-us/library/system.net.httpwebrequest.cookiecontainer.aspx
That'll do it, thanks!
0 comments:
Post a Comment