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
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.GetRespons
eStream. 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()
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!