Click here to Skip to main content
15,903,385 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I have probelem guys i am taking HMTL code from my local Site i am using this code
C#
         // We'll use WebClient class for reading HTML of web page
WebClient MyWebClient = new WebClient();

// Read web page HTML to byte array
Byte[] PageHTMLBytes;
if (textBox1.Text != "")
{

  PageHTMLBytes = MyWebClient.DownloadData(textBox1.Text);

  // Convert result from byte array to string
  // and display it in TextBox txtPageHTML
  UTF8Encoding oUTF8 = new UTF8Encoding();
  richTextBox1.Text = oUTF8.GetString(PageHTMLBytes);
}

buut this site first need Windows Authoristation i know User and password buuut how can i authorise with form it is erroring mee unauthorise beaocuse i don't enter any user and password i need that form that will take this password in password field and user in user field Help guys
Posted

1 solution

If the target page is using Windows authentication it's easy:

C#
         // We'll use WebClient class for reading HTML of web page
WebClient MyWebClient = new WebClient();
MyWebClient.Credentials = new NetworkCredential("myusername","mypassword");
 
// Read web page HTML to byte array
Byte[] PageHTMLBytes;
...


This will add the windows credentials into the authentication header.

If a different authentication mechanism is being used, you will need to provide the credentials in a different way. A really good example for forms authentication can be found at:
c# - WebClient accessing page with credentials - Stack Overflow[^]
 
Share this answer
 
Comments
GTR0123 6-Jan-16 9:16am    
TY that Peace of Code Helped Me Ty

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900