Tags: colleagues, environment, environmentuserdomainname, forms, herehad, ideasquotwe, net, userdomainname, web


On .Net » Web Forms

1,349 words with 1 Comments; publish: Sun, 16 Dec 2007 09:03:00 GMT; (10094.73, « »)

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.



Pat Long

All Comments

Leave a comment...

    • 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.

      #1; Sat, 08 Sep 2007 01:46:00 GMT