By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,827 Members | 2,155 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,827 IT Pros & Developers. It's quick & easy.

How to determine the domain for a NetworkCredential ???

P: n/a
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

Nov 15 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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
"Prehaut Anselme" <a.*******@stockadoo.net> wrote in message
news:Ov**************@tk2msftngp13.phx.gbl...
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

Nov 15 '05 #2

P: n/a

"Dave Loynd" <dl****@afts.com> a écrit dans le message de
news:eJ**************@TK2MSFTNGP11.phx.gbl...
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


Nov 15 '05 #3

P: n/a

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" <dl****@afts.com> a écrit dans le message d
news:eJ**************@TK2MSFTNGP11.phx.gbl..
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
Do you have some code you can post to show simply what/where your trouble

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

Nov 15 '05 #4

P: n/a
Thanks a lot,

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

Anselme
"Dave Loynd" <da********@verizon.net> a écrit dans le message de
news:31**********************************@microsof t.com...

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.
DL

Nov 15 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.