<p>This question is a follow up to my <a href="https://stackoverflow.com/questions/56279/export-aspx-to-html">previous question</a> about getting the HTML from an ASPX page. I decided to try using the webclient object, but the problem is that I get the login page's HTML because login is required. I tried "logging in" using the webclient object:</p>

<pre><code>WebClient ww = new WebClient();

 ww.DownloadString("Login.aspx?UserName=&amp;Password=");

 string html = ww.DownloadString("Internal.aspx");
</code></pre>

<p>But I still get the login page all the time. I know that the username info is not stored in a cookie. I must be doing something wrong or leaving out an important part. Does anyone know what it could be?</p>

[{'answer_id': 61221, 'author': 'Fire Lancer', 'author_id': 6266, 'author_profile': 'https://Stackoverflow.com/users/6266', 'pm_score': 1, 'selected': False, 'text': '<p>Well does opening the page in a brower with "Login.aspx?UserName=&amp;Password=" normaly work?<br>\nSome pages may not allow login using data provided in the url, and that it must be entered in the login form on the page and then submitted.</p>\n'}, {'answer_id': 61226, 'author': 'Lea Cohen', 'author_id': 278, 'author_profile': 'https://Stackoverflow.com/users/278', 'pm_score': 0, 'selected': False, 'text': '<p>@Fire Lancer: I asked myself that same question during my tests, so I checked, and it does work from a browser.</p>\n'}, {'answer_id': 61231, 'author': 'NakedBrunch', 'author_id': 3742, 'author_profile': 'https://Stackoverflow.com/users/3742', 'pm_score': 2, 'selected': False, 'text': '<p>Try setting the credentials property of the WebClient object</p>\n\n<pre><code>WebClient ww = new WebClient();\nww.Credentials = CredentialCache.DefaultCredentials;\nww.DownloadString("Login.aspx?UserName=&amp;Password=");\nstring html = ww.DownloadString("Internal.aspx");\n</code></pre>\n'}, {'answer_id': 61599, 'author': 'Fire Lancer', 'author_id': 6266, 'author_profile': 'https://Stackoverflow.com/users/6266', 'pm_score': 1, 'selected': False, 'text': '<p>The only other reason I can think of then is that the web page is intentionally blocking it from loggin in. If you have access to the code, take a look at the loggin system used to see if theres anything designed to block such logins.</p>\n'}, {'answer_id': 66374, 'author': 'Lea Cohen', 'author_id': 278, 'author_profile': 'https://Stackoverflow.com/users/278', 'pm_score': 0, 'selected': False, 'text': '<p>As the aspx page I was trying to get was in my own projct, I could use the Server.Execute method. More details in <a href="https://stackoverflow.com/questions/56279/export-aspx-to-html#66312">my answer</a> to my original question</p>\n'}, {'answer_id': 66448, 'author': 'Scott Gowell', 'author_id': 6943, 'author_profile': 'https://Stackoverflow.com/users/6943', 'pm_score': 2, 'selected': True, 'text': '<p>Just pass valid login parameters to a given URI. Should help you out. </p>\n\n<p><strong>If you don\'t have login information you shouldn\'t be trying to circumvent it.</strong></p>\n\n<pre>public static string HttpPost( string URI, string Parameters )\n      {\n         System.Net.WebRequest req = System.Net.WebRequest.Create( URI );\n         req.ContentType = "application/x-www-form-urlencoded";\n         req.Method = "POST";\n         byte[] bytes = System.Text.Encoding.ASCII.GetBytes( Parameters );\n         req.ContentLength = bytes.Length;\n         System.IO.Stream os = req.GetRequestStream();\n         os.Write( bytes, 0, bytes.Length );\n         os.Close();\n         System.Net.WebResponse resp = req.GetResponse();\n         if ( resp == null ) return null;\n         System.IO.StreamReader sr = new System.IO.StreamReader( resp.GetResponseStream() );\n         return sr.ReadToEnd().Trim();\n      }\n</pre>\n'}, {'answer_id': 125253, 'author': 'tyshock', 'author_id': 16448, 'author_profile': 'https://Stackoverflow.com/users/16448', 'pm_score': 0, 'selected': False, 'text': '<p>Use Firefox with the <a href="http://livehttpheaders.mozdev.org/" rel="nofollow noreferrer">LiveHttpHeaders</a> plugin.<br>\nThis will allow you to login via an actual browser and see EXACTLY what is being sent to the server.  My first question would be to verify that it isn\'t expecting a POST from the form.  The example URL you are loading is sending the info via a querystring GET. </p>\n'}, {'answer_id': 125263, 'author': 'Mark Cidade', 'author_id': 1659, 'author_profile': 'https://Stackoverflow.com/users/1659', 'pm_score': 1, 'selected': False, 'text': '<p>Use <a href="http://www.fiddler2.com" rel="nofollow noreferrer">Fiddler</a> to see the HTTP requests and responses that happen when you do it manually through the browser.</p>\n'}]
['https://Stackoverflow.com/questions/61217', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/278/']