The remote server returned an error: (401) Unauthorized

  • Thread starter Vijayakrishna Pondala
  • Start date
V

Vijayakrishna Pondala

Hi,

I am using the following C# code to connect to and download information from
a URL. (The pages are on JBoss server and we are using NTLM authentication
to connect to the server).

----
string url = "http://internal.ourcompany.com:8010/Page1";
WebRequest wreq = WebRequest.Create(url);
//Assign the default logon creadentials.
wreq.Credentials = CredentialCache.DefaultCredentials;
wreq.Timeout = 1000;
//Get the web response stream
WebResponse wres = wreq.GetResponse();
----
For some users, this code throws an error saying "The remote server returned
an error: (401) Unauthorized". When the user directly accesses the URL using
IE, he is able to see the information correctly.
Could someone help me out what is causing this error?

Thanks in advance,
Vijaya Krishna P.
 
R

Richard Blewett [DevelopMentor]

This is because the CredentialCache.DefaultCredentials uses your Windows credentials for authenication which the JBoss server doesn't know anything about

Create a new instance of the System.Net.NetworkCredentials class (it takes a user id, password and domain) and set the credentials of the web service proxy to that.

Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk

Hi,

I am using the following C# code to connect to and download information from
a URL. (The pages are on JBoss server and we are using NTLM authentication
to connect to the server).

----
string url = "http://internal.ourcompany.com:8010/Page1";
WebRequest wreq = WebRequest.Create(url);
//Assign the default logon creadentials.
wreq.Credentials = CredentialCache.DefaultCredentials;
wreq.Timeout = 1000;
//Get the web response stream
WebResponse wres = wreq.GetResponse();
----
For some users, this code throws an error saying "The remote server returned
an error: (401) Unauthorized". When the user directly accesses the URL using
IE, he is able to see the information correctly.
Could someone help me out what is causing this error?

Thanks in advance,
Vijaya Krishna P.



[microsoft.public.dotnet.languages.csharp]
 
W

William C.

hello
Richard Blewett said:
This is because the CredentialCache.DefaultCredentials uses your Windows
credentials for authenication which the JBoss server doesn't know anything
about
Create a new instance of the System.Net.NetworkCredentials class (it
takes a user id, password and domain) and set the credentials of the web
service proxy to that.
Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk

Hi,

I am using the following C# code to connect to and download information from
a URL. (The pages are on JBoss server and we are using NTLM authentication
to connect to the server).

----
string url = "http://internal.ourcompany.com:8010/Page1";
WebRequest wreq = WebRequest.Create(url);
//Assign the default logon creadentials.
wreq.Credentials = CredentialCache.DefaultCredentials;
wreq.Timeout = 1000;
//Get the web response stream
WebResponse wres = wreq.GetResponse();
----
For some users, this code throws an error saying "The remote server returned
an error: (401) Unauthorized". When the user directly accesses the URL using
IE, he is able to see the information correctly.
Could someone help me out what is causing this error?

Thanks in advance,
Vijaya Krishna P.



[microsoft.public.dotnet.languages.csharp]
 

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

Staff online

Members online

Forum statistics

Threads
473,734
Messages
2,569,441
Members
44,832
Latest member
GlennSmall

Latest Threads

Top