Domain name issue with .Net

In a project I need to know the name of the machine where the code run.

Everything ok on different servers (MyServerName for example) , exception of a new one I just finished to setup (Windows 2003).

The name I got is quite unusual, at least for me, NT AUTHORITY.

This is the code (response.write is for testing only)

Someone has an idea ?

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
   Dim ThisDomain As String = GetDomainName()
   response.write(ThisDomain)
End Sub

Public Function GetDomainName() As String
   Dim tmp As String = Principal.WindowsIdentity.GetCurrent.Name()
   Dim pos As Short Dim result As String pos = InStr(tmp, "\")
   If pos <> 0 Then
    result = Microsoft.VisualBasic.Left(tmp, pos - 1) 
   End If
   Return result
End Function

 

4 Comments

  • It looks like you're grabbing the account name instead of the machine name. If you're trying to get the machine name, try System.Environment.MachineName (I think that's it).

  • Dim tmp As String = Principal.WindowsIdentity.GetCurrent.Name()



    2003 does change some things....



    NT AUTHORITY is an &quot;Account&quot; is the server impersonating a user?

    has the server switched context from default to impersonate at the time you call that fn?



    hey I bet on win 2k and before iis was running in such a way that the user name was blank..

    so it did not stick a &quot;\name&quot; on the credtentils get it??

  • By default in W2K3 the ASP.NET worker proecess runs under NETWORK Services Identity which is NTSecurity user. Even if you change the machine.config it will work under the above context only.

  • NT AUTHORITY\SYSTEM or NT AUTHORITY\Local Service are some examples of what this could be. Print out the whole string istead of doing .Left. I bet there is an account name on the right side of the \ but it probably won't be the machine name. It will be the name of the account the code is running under.

Comments have been disabled for this content.