July 28, 2008 at 11:06 am
How to get windows user ID in C# web application# web application?
To clarify, I am talking about login ID that user uses to login to his working machine. (he/she has to press Ctrl-Alt-Del and enter login and password to start working)
I was looking around and one of the suggestion was to use: System.Environment.UserName;
But, this gives (by my opinion) account name under which the application is logged to the server that hosts application. In my case I get "ASPNET" and that is not my windows ID.
This only gives my account "domain\srayabharapu" System.Security.Principal.WindowsIdentity.GetCurrent().Name;
I assume that for this I will have to connect to Active Directory. How can I do that and how to query Active Directory.
this is needed because i need to add groupusername to set the user for an item.
Thanks.
July 29, 2008 at 1:55 am
Hi,
// 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");
Hope this code will help you.
Wish u all the best
Sandip Shinde
July 29, 2008 at 11:27 am
Thanks for the reply.
string userName = Request.ServerVariables["AUTH_USER"]; //Finding with name
This is the answer which am looking at.
August 13, 2009 at 5:36 am
Try this .It also works
Response.Write(Page.User.Identity.Name);
Himabindu Vejella
spaces.msn.com
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply