0

I am trying to extract the html of my current page. To do it is pretty simple

private string GetHtml()
{
    WebClient myClient = new WebClient();
    string myPageHTML = null;


    byte[] requestHTML;
    // Gets the url of the page
    string currentPageUrl = Request.Url.ToString();

    UTF8Encoding utf8 = new UTF8Encoding();



    requestHTML = myClient.DownloadData(currentPageUrl);

    myPageHTML = utf8.GetString(requestHTML);

    Response.Write(myPageHTML);

    return myPageHTML;

}

But my problem I am having is, if this page is behind a secure section, the WebClient is effectively unauthenticated, so the server will just return the "Login screen" instead.

Can I pass my cookie or my session to this WebClient?

Crudler
  • 2,194
  • 3
  • 30
  • 57
  • check this link - http://stackoverflow.com/questions/1883655/how-do-i-authenticate-a-webclient-request, or find `ASP.NET_SessionId` cookie and set that in webclient request, if you need code for this, i can help you on this. – Arindam Nayak Oct 21 '14 at 16:46
  • Thanks. I understand the concept, but not sure how to implement – Crudler Oct 21 '14 at 22:45

0 Answers0