473,396 Members | 1,590 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to determine the domain for a NetworkCredential ???

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
4 19784
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

"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

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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Eddie Lipshultz | last post by:
I'm working with the NetworkCredential class. I'm making the correct call and it returns that everything is okay using: NetworkCredential sc = new NetworkCredential("MyAccount", sPassword,...
2
by: Prathiraj | last post by:
Hi All, I'm trying to access a web page from C# code. Since I'm behind a firewall/proxy, I creat a webproxy and NetworkCredential to access the web page. It works fine. In this way, I have to...
2
by: Robert Bryan via .NET 247 | last post by:
Hello, Is there any way to determine which server answers an LDAP query? One that is not directed at a particular server that is. ie. DirectoryEntry oUser=new...
4
by: Dave | last post by:
Greetings, I have a web application that will be hosted on our intranet. I would like to determine, via code the user's windows login name and domain in the following format: DOMAIN\loginname...
0
by: Jan Wrage | last post by:
Hi! Currently i'm working on a program that should let u administer every domain on the network. First step is to enumerate all domains with DirectoryEntry("WinNT:") That takes a long time...
3
by: Patrick Fogarty | last post by:
I am programming what is to be a web service client that will use an HTTP-POST to request and retrieve data. The remote server (written in java for what it's worth) requires basic authentication...
8
by: Jim in Arizona | last post by:
I was trying to have an email sent when the page loads but having some trouble with it. Our server is an IIS 6.0 with Framework 2.0. It is set to windows authentication (not anonymous). I...
1
by: Bob | last post by:
Hi Trying out NetworkCredential class. The code from the help example fails when you try to do an add to the Credential cache. 'Invalid URI. The format of the URI can not be determined.' I don't...
2
by: Tuncer Erhamza | last post by:
Hi! Another web application (domain) call our application. We want to determine in our application which domain call. Thanks.
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.