Credentials Modification

Oct 24, 2008 at 6:09 PM

I've noticed quite a few people asking about credentials modifications.

For Forms Authentication out http://www.dotnetjunkies.com/WebLog/joshuagough/archive/2006/01/20/134825.aspx

Here is a modification I used to add credentials to the Web Request.

In HtmlWeb.cs:
 
1.) create the following private fields: 

 

 

private string _userName;

 

 

private string _password;

2.) Create a new constructor:  

 

 

public HtmlWeb(string userName, string password)

 

{

_userName = userName;

_password = password;

}

3.) Add the following to the HttpStatusCode Get() method

 

private

HttpStatusCode Get(Uri uri, string method, string path, HtmlDocument doc)

 

{

 

 

 

 

if(!string.IsNullOrEmpty(_userName) && !string.IsNullOrEmpty(_password))

 

{

req.Credentials =

new NetworkCredential(_userName, _password);

 

}