Retrieving Windows User name/ID
-
Hi all I've created a ASP.NET/VB.NET application to maintain a database via a datagrid and was looking to retrieve the Windows username of the current user of the application so that when they click to update any changes they make, a field in the database will update showing that user as the last person to update that record. I've set the authentication to 'windows' in the webconfig file, could anyone point me to the code I would need to retrieve the windows username? Many Thanks
Rob
-
Hi all I've created a ASP.NET/VB.NET application to maintain a database via a datagrid and was looking to retrieve the Windows username of the current user of the application so that when they click to update any changes they make, a field in the database will update showing that user as the last person to update that record. I've set the authentication to 'windows' in the webconfig file, could anyone point me to the code I would need to retrieve the windows username? Many Thanks
Rob
This is better asked in the ASP.NET Forum. I don't see how you're going to get the username from the client without some kind of authentication on the client side and sending that information to the server, possibly storing it in the session object. But, that's about as far as my very limited ASP.NET experience will take me on this one.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007 -
This is better asked in the ASP.NET Forum. I don't see how you're going to get the username from the client without some kind of authentication on the client side and sending that information to the server, possibly storing it in the session object. But, that's about as far as my very limited ASP.NET experience will take me on this one.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007 -
Hi all I've created a ASP.NET/VB.NET application to maintain a database via a datagrid and was looking to retrieve the Windows username of the current user of the application so that when they click to update any changes they make, a field in the database will update showing that user as the last person to update that record. I've set the authentication to 'windows' in the webconfig file, could anyone point me to the code I would need to retrieve the windows username? Many Thanks
Rob
HttpContext.Current.User.Identity.Name.ToString() returns the domain and username seperated by a slash. The following will get the username. Dim UserName as String Dim UserLoginDomainAndID as string[] UserLoginDomainAndID = HttpContext.Current.User.Identity.Name.ToString().Split(new char [] {'\\'}) UserName = UserLoginDomainAndID[UserLoginDomainAndID.Length-1] I converted this from my c# code so appoligies if it's not quite vb.net, but it should be close. Oh and I used this on an asp.net site that did windows authentication. Unauthenticated this will give you nothing. Not certain what would be returned under other authentication.
topcoderjax - Remember, Google is your friend.