Home All Groups Group Topic Archive Search About

Proxy server authentication

Author
25 Jun 2006 11:55 PM
alanw
I am developing a C#.NET Windows forms client-server application. The client
software needs to be able to access the server software regardless of the
proxy server configuration of the machine on which the client runs. Using the
following code, the client can access the server via any proxy server
configuration other than one which requires authentication.

        IWebProxy iwp20 = WebRequest.DefaultWebProxy;


The client needs to be able to handle authenticated proxy servers without
prompting the user for login credentials and without any hardcoding of
username, password, and domain. I've searched the Internet looking for advice
on how to solve this problem. I have tried various suggestions including the
following but nothing seems to work.

        NetworkCredential nc = new NetworkCredential( "username", "password",
"domain" );
        System.Uri wsUri = new System.Uri( this.Url );
        System.Net.WebRequest wr = this.GetWebRequest( wsUri );
        wr.Headers.Add( "Keep-Alive:true" );
        wr.Proxy.Credentials=nc;

Please advise.

Thanks

Alan

Author
26 Jun 2006 6:42 AM
Raymond Yuen
Hi Alan,

Have you tried the DefaultCredential property in the CredentialCache object
instead of creating a new NetworkCredential object?

Raymond

Show quoteHide quote
"alanw" wrote:

> I am developing a C#.NET Windows forms client-server application. The client
> software needs to be able to access the server software regardless of the
> proxy server configuration of the machine on which the client runs. Using the
> following code, the client can access the server via any proxy server
> configuration other than one which requires authentication.
>
>         IWebProxy iwp20 = WebRequest.DefaultWebProxy;
>
>
>  The client needs to be able to handle authenticated proxy servers without
> prompting the user for login credentials and without any hardcoding of
> username, password, and domain. I've searched the Internet looking for advice
> on how to solve this problem. I have tried various suggestions including the
> following but nothing seems to work.
>
>         NetworkCredential nc = new NetworkCredential( "username", "password",
> "domain" );
>         System.Uri wsUri = new System.Uri( this.Url );
>         System.Net.WebRequest wr = this.GetWebRequest( wsUri );
>         wr.Headers.Add( "Keep-Alive:true" );
>         wr.Proxy.Credentials=nc;
>
> Please advise.
>
> Thanks
>
> Alan
>
Author
30 Jun 2006 2:28 AM
alanw via DotNetMonster.com
Thanks, Raymond, this works. Alan.

Raymond Yuen wrote:
Show quoteHide quote
>Hi Alan,
>
>Have you tried the DefaultCredential property in the CredentialCache object
>instead of creating a new NetworkCredential object?
>
>Raymond
>
>> I am developing a C#.NET Windows forms client-server application. The client
>> software needs to be able to access the server software regardless of the
>[quoted text clipped - 22 lines]
>>
>> Alan