473,325 Members | 2,442 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,325 software developers and data experts.

NetworkCredential and WindowsIdentity

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
Nov 15 '05 #1
2 18980
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]
- mv*@spam.guard.caspershouse.com

"Prathiraj" <pr*******@hotmail.com> wrote in message
news:09****************************@phx.gbl...
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

Nov 15 '05 #2
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");
Nicholas Paldino [.NET/C# MVP] wrote:
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]
- mv*@spam.guard.caspershouse.com

"Prathiraj" <pr*******@hotmail.com> wrote in message
news:09****************************@phx.gbl...
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


Nov 16 '05 #3

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,...
8
by: BLiTZWiNG | last post by:
After playing with the code shown and utilising Willy Denyottes' help, I have come to the conclusion that there is some form of difference between the managed WindowsIdentity.Impersonate() over the...
3
by: diephouse | last post by:
I seem to be having a problem accessing networks shares. For example, I try the following code: File.Exists(@"\\SERVER\share"); always returns false! Or even if I map the drive ...
3
by: Kevin Burton | last post by:
This is more of a solution that raised a question. I have a Web service that does not allow anonymous users. For debugging I put in the following lines in my Web Service: WindowsIdentity wi =...
8
by: Razak | last post by:
Hi, I have a class which basically do Impersonation in my web application. From MS KB sample:- ++++++++++++++++++++code starts Dim impersonationContext As...
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...
1
by: Roger | last post by:
I have a desktop and laptop for development. Both are xps and both are sp2 and both are update to date with security patches. On my desktop when I run the LogonUser api function call. It...
2
by: YK | last post by:
Hi I have a Web Application that connects to Exchange WebDAV using a class that I found on http://www.codeproject.com/dotnet/exdav.asp. This class requires a NetworkCredential object in order to...
0
by: Ed Sutton | last post by:
Is there a FileSecurity method that can determine if the current WindowsIdentity has write access to a file? I can get the current windows identity and use FileSecurity to return the ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.