How to determine the domain for a NetworkCredential ???

P

Prehaut Anselme

Hi,

I need to create a WebRequest with an automatic proxy

I have the specification of this porxy (host & port)

I ask the user their own login and password, but the proxy tells me that the
connection need an authentification.

During the creation of a NetworkCredential you can define the login, the
password AND the domain.

But how can I retrieve this domain ???

It's particulary needed for users under Windows NT

Have you some hints ???

Thx
Anselme
 
D

Dave Loynd

I'm a little rusty in this area, but generally I think the user would supply
the domain, supposing they know which domain they log into in the first
place. If you leave the domain blank, Windows will attempt to authenticate
the user in the default domain as set in IIS. That having been said, there
is no way I'm aware of to easily retrieve the domain name from the outside.

Do you have some code you can post to show simply what/where your troubles
begin?
DL
 
P

Prehaut Anselme

Dave Loynd said:
I'm a little rusty in this area, but generally I think the user would supply
the domain, supposing they know which domain they log into in the first
place. If you leave the domain blank, Windows will attempt to authenticate
the user in the default domain as set in IIS. That having been said, there
is no way I'm aware of to easily retrieve the domain name from the outside.

Do you have some code you can post to show simply what/where your troubles
begin?
DL

The code is very simply.
I create a webrequest

System.Net.HTTPWebRequest req = (Systen.Net.HTTPWebRequest)
System.Net.WebRequest.create(adress);

ifi've found that there is a proxy I set up this proxy

System.Net.WebProxy myproxy = new System.Net.WebProxy(proxyHost, proxyPort);
req.Proxy = myProxy;

I try to establish a connection through this proxy

req.GetResponse();

If en exception is thrown and if this Exception is a 407 WebException
(authenticate required) I ask the user for is login and password and i do
this process

System.Net.HTTPWebRequest req = (Systen.Net.HTTPWebRequest)
System.Net.WebRequest.create(adress);
System.Net.WebProxy myproxy = new System.Net.WebProxy(proxyHost, proxyPort);
myProxy.Credential = new System.Net.Credentials(login, password);
req.Proxy = myProxy;

But here, with a NT User the request is still a 407 Exception.

I think it's because I need to create the credentials like this :

myProxy.Credential = new System.Net.Credentials(login, password, domain);

But I don't know where to retrieve this information, in the registry (like
the proxy information) ?

Thx
Anselme
 
G

Guest

Have you tried assigning the Credentials to the WebRequest object in addition to the Proxy? From there you might parse the current user's logon domain from the current Thread object and pass that along

string domain = System.Threading.Thread.CurrentPrincipal.Identity.Name; // == MY_DOMAIN\USERNAM

System.Net.HTTPWebRequest req = (Systen.Net.HTTPWebRequest
System.Net.WebRequest.create(adress)
System.Net.WebProxy myproxy = new System.Net.WebProxy(proxyHost, proxyPort)
myProxy.Credential = new System.Net.Credentials(login, password, domain)
req.Credential = myProxy.Credential
req.Proxy = myProxy

One warning: the domain the user logs into normally may not necessarily be the domain they authenticate on to access the proxy. It could be the local proxy machine, in which case you would need to determine the name of that machine and pass that along instead.

D


----- Prehaut Anselme wrote: ----


Dave Loynd said:
I'm a little rusty in this area, but generally I think the user woul suppl
the domain, supposing they know which domain they log into in the firs
place. If you leave the domain blank, Windows will attempt t authenticat
the user in the default domain as set in IIS. That having been said ther
is no way I'm aware of to easily retrieve the domain name from th outside
begin
D

The code is very simply
I create a webreques

System.Net.HTTPWebRequest req = (Systen.Net.HTTPWebRequest
System.Net.WebRequest.create(adress)

ifi've found that there is a proxy I set up this prox

System.Net.WebProxy myproxy = new System.Net.WebProxy(proxyHost, proxyPort)
req.Proxy = myProxy

I try to establish a connection through this prox

req.GetResponse()

If en exception is thrown and if this Exception is a 407 WebExceptio
(authenticate required) I ask the user for is login and password and i d
this proces

System.Net.HTTPWebRequest req = (Systen.Net.HTTPWebRequest
System.Net.WebRequest.create(adress)
System.Net.WebProxy myproxy = new System.Net.WebProxy(proxyHost, proxyPort)
myProxy.Credential = new System.Net.Credentials(login, password)
req.Proxy = myProxy

But here, with a NT User the request is still a 407 Exception

I think it's because I need to create the credentials like this

myProxy.Credential = new System.Net.Credentials(login, password, domain)

But I don't know where to retrieve this information, in the registry (lik
the proxy information)

Th
Anselm
 
P

Prehaut Anselme

Thanks a lot,

I've not tried this (perhaps because I don't know this), I but this in my
code

Anselme


Dave Loynd said:
Have you tried assigning the Credentials to the WebRequest object in
addition to the Proxy? From there you might parse the current user's logon
domain from the current Thread object and pass that along:
string domain = System.Threading.Thread.CurrentPrincipal.Identity.Name; // == MY_DOMAIN\USERNAME

System.Net.HTTPWebRequest req = (Systen.Net.HTTPWebRequest)
System.Net.WebRequest.create(adress);
System.Net.WebProxy myproxy = new System.Net.WebProxy(proxyHost, proxyPort);
myProxy.Credential = new System.Net.Credentials(login, password, domain);
req.Credential = myProxy.Credential;
req.Proxy = myProxy;

One warning: the domain the user logs into normally may not necessarily be
the domain they authenticate on to access the proxy. It could be the local
proxy machine, in which case you would need to determine the name of that
machine and pass that along instead.
 

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

Top