Programmatically get HTML of secure page

I've created a .aspx page that contains data populated from a Repeater control, and an 'Email' button that sends the current page as an HTML e-mail to the e-mail address input in a text box. Therefore, I need to extract the HTML of the current page and place it in a String variable, but I'm having a real tough time doing this.  My page exists in a secure site, so if you have navigated to the page in question, you are already logged in to the secure server.  A page created for a project similar to the one I'm working on uses something like this to get the HTML of the current, secure page (I didn't create that page). It used the following to extract the HTML:

Dim textWriter As TextWriter
Server.Execute("Page.aspx?queryParam1=" & sParam, textWriter)
Dim sHTML as String
sHTML = oTextWriter.ToString()
Dim email as SmtpClient 

Open in new window

However, even though this project is set up very similarly to mine, and is currently properly working,  my page hangs up when it makes a call to the Server.Execute method (Page.aspx is the current page containing the Email button).

I've tried a different way: Using HttpWebRequest and HttpWebResponse, and getting the HttpWebResponse.GetResponseStream.  However, what I found with this is that what is actually returned is the HTML for the Login Page to our server, NOT the current page's HTML.  Here is what I tried.

Dim oRequest as HttpWebRequest
Dim oResponse as HttpWebResponse
oRequest = WebRequest.Create(sCurrentPageUri)  'passed the current page's absolute uri
oRequest.Credentials = CredentialCache.DefaultCredentials ' ?
oResponse = oRequest.GetResponse()
Dim sReader as StreamReader = oResponse.GetResponseStream()
Dim sHTML as String = sReader.ReadToEnd()

Open in new window

Any comments on this would be appreciated. This is a first-time post, this site seemed like a great resource and that is exactly what I need right now. Something that I should be very simple has consumed much more time that I expected to figure out! If you need more details, please let me know. Thanks!
Who is Participating?
As its the current page, try Page.Render method to get the HTML
Pep_00Author Commented:
Medo, thanks for the comment, but I think that the link demonstrates sort of what I am doing in the second snippet, where I am not getting the current page's HTML, but rather the HTML of the login page for the secure server (unless I'm missing something subtle).  I am perhaps not doing something correctly with the credentials of the request.  CodeCruiser, thank you for the reply - I am relatively new to .NET, and didn't know about Page.Render method, but I think that is what I need. Thanks!
Amandeep Singh BhullarCommented:
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.