Home All Groups Group Topic Archive Search About

Set credentials to a web request

Author
4 Apr 2006 6:24 AM
Nonnie
Hi,
I'm trying to run an automated test (using NTime tool) on a web application
(windows authentication). All calls in this web app are intercepted by a
custom httpModule. I'm setting credentials to the web request so that the
authentication passes but this doesn't seem to work:

NetworkCredential obj = new NetworkCredential();
obj.UserName = @"domain\username";
obj.Password = "test123";
HttpWebRequest myRequest = (HttpWebRequest)
HttpWebRequest.Create("https://testsite.com/testapp/samplepage.aspx");
myRequest.Credentials = obj;

Please suggest the solution.
Thanks

Author
4 Apr 2006 8:23 AM
Vadym Stetsyak
Hello, Nonnie!

N> NetworkCredential obj = new NetworkCredential();
N> obj.UserName = @"domain\username";
N> obj.Password = "test123";
N> HttpWebRequest myRequest = (HttpWebRequest)
N> HttpWebRequest.Create("https://testsite.com/testapp/samplepage.aspx");
N> myRequest.Credentials = obj;

What type authentication do you use?

You can try this

CredentialCache myCache = new CredentialCache();

NetworkCredential netCredential = new  NetworkCredential(UserName,SecurelyStoredPassword,Domain);

myCache.Add(new Uri("https://testsite.com/testapp/samplepage.aspx"),"Basic", netCredential);
myCache.Add(new Uri("https://testsite.com/testapp/samplepage.aspx"),"Digest", netCredential);
myCache.Add(new Uri("https://testsite.com/testapp/samplepage.aspx"),"Negotiate", netCredential);

myRequest.Credentials = myCache;

--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com

AddThis Social Bookmark Button