Badly stuck, Please help

D

Deepak

Hi Experts,
I have a page in my inetpub\wwwroot called testpage.asp. I have removed
anonymous access to this page and have checked windows integrated security.
Now when I try to access this page from code I get a 401 error. Why is this?
I am able to acces the page from IE without any problem. what can do to get
around this problem.
here's my code :

try
{
WebClient wc = new WebClient();
NameValueCollection nvc = new NameValueCollection();
string uri;
uri = "http://localhost/testpage.asp";
NetworkCredential nc = new NetworkCredential("raj","");
wc.UploadValues(uri,nvc);

}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
 
D

Deepak

in addition to this it does not matter if i do this or not

NetworkCredential nc = new NetworkCredential("raj","");
wc.Credentials = nc;
 
D

Deepak

Thanks Rick, Thanks Martin,
I did have the windows authentication enabled for the root directory, still
no luck.

I got my credentials as suggested by Martin:
NetworkCredential nc = (NetworkCredential)
CredentialCache.DefaultCredentials;

It works perfectly.

Once again guys thanks a lot, you have solved a major problem for me. Your
efforts are much appreciated.

With Regards



Deepak
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top