NetworkCredential and WindowsIdentity

P

Prathiraj

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 give the username and password for
creating the NetworkCredential object. Is there anyway
that I can get the NetworkCredential object from the
logged on user?

Basically the requirement is to supply the same credential
as of the logged in user to the web proxy.

Help!!

regards,
Prathiraj
 
N

Nicholas Paldino [.NET/C# MVP]

Prathiraj,

No, you can not. While you can get the username of the person that is
currently logged on, you can not get the password. You will have to get
this from the user themselves.

Hope this helps.
 
D

dobrik

here is an example of usage of CredentialCache.DefaultCredentials

// Ensure Directory Security settings for default web site in IIS is
"Windows Authentication".
string url = "http://localhost";
// Create a 'HttpWebRequest' object with the specified url.
HttpWebRequest myHttpWebRequest =
(HttpWebRequest)WebRequest.Create(url);
// Assign the credentials of the logged in user or the user being
impersonated.
myHttpWebRequest.Credentials = CredentialCache.DefaultCredentials;
// Send the 'HttpWebRequest' and wait for response.
HttpWebResponse myHttpWebResponse =
(HttpWebResponse)myHttpWebRequest.GetResponse();
Console.WriteLine("Authentication successful");
Console.WriteLine("Response received successfully");

Prathiraj,

No, you can not. While you can get the username of the person that is
currently logged on, you can not get the password. You will have to get
this from the user themselves.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Prathiraj said:
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 give the username and password for
creating the NetworkCredential object. Is there anyway
that I can get the NetworkCredential object from the
logged on user?

Basically the requirement is to supply the same credential
as of the logged in user to the web proxy.

Help!!

regards,
Prathiraj
 

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