Windows Develop Bookmark and Share   
 index > Windows Forms General > Environment.UserDomainName
 

Environment.UserDomainName

One of my colleagues asked this question recently and I was wondering if anybody here
had any ideas

"We are using Environment.UserDomainName in the new Corporate System for some of the security checking. An interesting point arose today. If you are on a machine logged onto a domain, Environment.UserDomainName will return the name of the domain, UNLESS there is an account on the local machine with the same name, in which case it will return the name of the local machine. This means you can not be guaranteed that it will return the results you are expecting. 
 
The obvious workaround is to use Environment.GetEnvironmentVariable("USERDOMAIN"), but the problem with that is it does not take any account of things like 'Run As'. Anybody got any ideas of a bullet-proof way to determine the domain the current account is a member of? I thought of using System.Security.Principal.WindowsIdentity.GetCurrent().Name, but that doesn't work for Run As on a machine that is not part of the domain.
"

Thanks

Pat Long 
MigrationUser 1  Thursday, July 10, 2003 4:33 PM
I have an intranet app that uses remoting hosted in IIS.  To discover credentials, I use the following:

            Dim wp As New System.Security.Principal.WindowsPrincipal(System.Security.Principal.WindowsIdentity.GetCurrent())
            Dim s As String = wp.Identity.Name


and I haven't had a problem with it.
MigrationUser 1  Friday, July 11, 2003 10:23 AM

You can use google to search for other answers

Custom Search

More Threads

• C#: Can't Get a Form to Scale
• showing notepad in my application
• timer tick running before application starts
• Check versioning of client applications
• Can't change resolution properties on an Image
• Newbie Closing Forms
• Multiple forms?
• How to get scrolling text display ?
• How to create more restrictive custom attribute
• Datetimepicker bug