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="kaverao" data-source="post: 3942870" data-attributes="member: 60957"><p><strong>Exporting exact page to the "html" and then to "pdf" - struck with a problem</strong></p><p></p><p><span style="color: Blue">Hi,</span></p><p><span style="color: Blue">I am struck with a similar problem. I have a web page that consists of many gridviews one inside other and can be drilled down by the user (AJAX panel refresh).</span></p><p><span style="color: Blue">I am using the below function to save the page as HTML. <strong><u>The problem with below code is - it uses System.Web.HttpContext.Current.Request.Url and renders the page ; Hence the drilldowns of grids are not saved in the same state in the html.</u></strong> [example - I have 5 items on the grid. I click 2nd item to see the "full details" which drills down the row and displays another grid below. But the code below <strong>takes Request.url and renders and saves</strong>. So, my drilldowns won't be reflected in the HTML. Please help me solve the problem.</span></p><p></p><p>private void SaveWebPage_as_HTML()</p><p> {</p><p> </p><p> // Initialize the WebRequest.</p><p> string urlToConvert = (System.Web.HttpContext.Current.Request.Url).ToString();</p><p> WebRequest myRequest = WebRequest.Create(urlToConvert);</p><p> // Return the response. </p><p> WebResponse myResponse = myRequest.GetResponse();</p><p></p><p> // Obtain a 'Stream' object associated with the response object.</p><p> Stream ReceiveStream = myResponse.GetResponseStream();</p><p> Encoding encode = System.Text.Encoding.GetEncoding("utf-8");</p><p></p><p> // Pipe the stream to a higher level stream reader with the required encoding format. </p><p> </p><p> StreamReader readStream = new StreamReader(ReceiveStream, encode, true, 255);</p><p></p><p> // Read 256 charcters at a time. </p><p> Char[] read = new Char[256];</p><p> int count = readStream.Read(read, 0, 256);</p><p> using (StreamWriter sw = new StreamWriter("Invoice1.html"))</p><p> {</p><p> while (count > 0)</p><p> {</p><p> // Dump the 256 characters on a string and display the string onto the console.</p><p> String str = new String(read, 0, count);</p><p> sw.Write(str);</p><p> count = readStream.Read(read, 0, 256);</p><p> }</p><p></p><p> }</p><p></p><p> // Close the response to free resources.</p><p> myResponse.Close();</p><p> }</p><p></p><p></p><p><span style="color: Blue">One way i thought was ... to <strong>tap the current page's response stream</strong>. Coded something like this...</span></p><p>// Pipe the stream to a higher level stream reader with the required encoding format. </p><p> Stream ReceiveStream = System.Web.HttpContext.Current.Response.OutputStream; </p><p> StreamReader readStream = new StreamReader(ReceiveStream, encode, true, 255);</p><p></p><p><span style="color: blue">But when i run this i am getting "<strong>Can not read stream</strong>" error when </span><span style="color: Red">StreamReader </span> <span style="color: blue">is executed. Anyway to resolve this???. Am i doing correct thing, in 1st place? I appreciate any help...</span></p><p><span style="color: blue"></span></p><p><span style="color: blue">Thanks - Rao</span></p></blockquote><p></p>
[QUOTE="kaverao, post: 3942870, member: 60957"] [b]Exporting exact page to the "html" and then to "pdf" - struck with a problem[/b] [COLOR="Blue"]Hi, I am struck with a similar problem. I have a web page that consists of many gridviews one inside other and can be drilled down by the user (AJAX panel refresh). I am using the below function to save the page as HTML. [B][U]The problem with below code is - it uses System.Web.HttpContext.Current.Request.Url and renders the page ; Hence the drilldowns of grids are not saved in the same state in the html.[/U][/B] [example - I have 5 items on the grid. I click 2nd item to see the "full details" which drills down the row and displays another grid below. But the code below [B]takes Request.url and renders and saves[/B]. So, my drilldowns won't be reflected in the HTML. Please help me solve the problem.[/COLOR] private void SaveWebPage_as_HTML() { // Initialize the WebRequest. string urlToConvert = (System.Web.HttpContext.Current.Request.Url).ToString(); WebRequest myRequest = WebRequest.Create(urlToConvert); // Return the response. WebResponse myResponse = myRequest.GetResponse(); // Obtain a 'Stream' object associated with the response object. Stream ReceiveStream = myResponse.GetResponseStream(); Encoding encode = System.Text.Encoding.GetEncoding("utf-8"); // Pipe the stream to a higher level stream reader with the required encoding format. StreamReader readStream = new StreamReader(ReceiveStream, encode, true, 255); // Read 256 charcters at a time. Char[] read = new Char[256]; int count = readStream.Read(read, 0, 256); using (StreamWriter sw = new StreamWriter("Invoice1.html")) { while (count > 0) { // Dump the 256 characters on a string and display the string onto the console. String str = new String(read, 0, count); sw.Write(str); count = readStream.Read(read, 0, 256); } } // Close the response to free resources. myResponse.Close(); } [COLOR="Blue"]One way i thought was ... to [B]tap the current page's response stream[/B]. Coded something like this...[/COLOR] // Pipe the stream to a higher level stream reader with the required encoding format. Stream ReceiveStream = System.Web.HttpContext.Current.Response.OutputStream; StreamReader readStream = new StreamReader(ReceiveStream, encode, true, 255); [COLOR="blue"]But when i run this i am getting "[B]Can not read stream[/B]" error when [/COLOR][COLOR="Red"]StreamReader [/COLOR] [COLOR="blue"]is executed. Anyway to resolve this???. Am i doing correct thing, in 1st place? I appreciate any help... Thanks - Rao[/COLOR] [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
ASP .Net
Using WebRequest to get the rendered HTML of protected page, returns login page
Top