Menu
Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
ASP .Net
Using WebRequest to get the rendered HTML of protected page, returns login page
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="Stephen Miller" data-source="post: 358558"><p>I have an ASPX report and I want to capture the rendered HTML and</p><p>write to a file on the webserver. Several posts suggest using</p><p>WebRequest to make a second call to the page, and screen-scrape the</p><p>resulting HTML. The technique typically described is:</p><p></p><p>'-- Get the current URL and request page</p><p>Dim url As String =</p><p>System.Web.HttpContext.Current.Request.Url.AbsoluteUri</p><p>Dim req As System.Net.WebRequest = System.Net.WebRequest.Create(url)</p><p></p><p>Dim result As System.Net.WebResponse = req.GetResponse()</p><p>Dim ReceiveStream As Stream = result.GetResponseStream()</p><p></p><p>Dim read() As Byte = New Byte(512) {}</p><p>Dim bytes As Integer = ReceiveStream.Read(read, 0, 512)</p><p></p><p>'-- Read contents and append to StringBuilder</p><p>Dim sbPage As New System.Text.StringBuilder()</p><p>While (bytes > 0)</p><p>Dim encode As System.Text.Encoding =</p><p>System.Text.Encoding.GetEncoding("utf-8")</p><p>sbPage.Append(encode.GetString(read, 0, bytes))</p><p>bytes = ReceiveStream.Read(read, 0, 512)</p><p>End While</p><p></p><p>My problem is that</p><p>Firstly, doesn't this necessitate a second round trip to the server</p><p>adding performance overheads?</p><p>Secondly, my report is password protected (authentication mode is</p><p>Forms) and this technique redirects to the designated login form.</p><p></p><p>Is there another way to get a string representation of the rendered</p><p>HTML? I have been fooling around with the OutputStream without any</p><p>luck.</p><p></p><p></p><p>As a side note, writing the HTML to file is part of a dodgy workaround</p><p>that shells to a DOS program and converts the resulting HTML to PDF</p><p>format, prior to flushing the current response and sending the PDF</p><p>instead. I have looked at dozens of commercial products but haven't</p><p>found one that can convert the rendered ASPX page to PDF on the fly</p><p>(allowing me to provide all report layout in ASPX mark-up). Is anyone</p><p>aware of a commercial product that can resultant do this?</p><p></p><p>I know SQL Server 2000 Reporting Services has just become available,</p><p>but I don't have VS2003.</p><p></p><p>Regards,</p><p></p><p>Stephen</p></blockquote><p></p>
[QUOTE="Stephen Miller, post: 358558"] I have an ASPX report and I want to capture the rendered HTML and write to a file on the webserver. Several posts suggest using WebRequest to make a second call to the page, and screen-scrape the resulting HTML. The technique typically described is: '-- Get the current URL and request page Dim url As String = System.Web.HttpContext.Current.Request.Url.AbsoluteUri Dim req As System.Net.WebRequest = System.Net.WebRequest.Create(url) Dim result As System.Net.WebResponse = req.GetResponse() Dim ReceiveStream As Stream = result.GetResponseStream() Dim read() As Byte = New Byte(512) {} Dim bytes As Integer = ReceiveStream.Read(read, 0, 512) '-- Read contents and append to StringBuilder Dim sbPage As New System.Text.StringBuilder() While (bytes > 0) Dim encode As System.Text.Encoding = System.Text.Encoding.GetEncoding("utf-8") sbPage.Append(encode.GetString(read, 0, bytes)) bytes = ReceiveStream.Read(read, 0, 512) End While My problem is that Firstly, doesn't this necessitate a second round trip to the server adding performance overheads? Secondly, my report is password protected (authentication mode is Forms) and this technique redirects to the designated login form. Is there another way to get a string representation of the rendered HTML? I have been fooling around with the OutputStream without any luck. As a side note, writing the HTML to file is part of a dodgy workaround that shells to a DOS program and converts the resulting HTML to PDF format, prior to flushing the current response and sending the PDF instead. I have looked at dozens of commercial products but haven't found one that can convert the rendered ASPX page to PDF on the fly (allowing me to provide all report layout in ASPX mark-up). Is anyone aware of a commercial product that can resultant do this? I know SQL Server 2000 Reporting Services has just become available, but I don't have VS2003. Regards, Stephen [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
ASP .Net
Using WebRequest to get the rendered HTML of protected page, returns login page
Top