Why is the value of System.Environment.MachineName uppercase?

My machine name is less (I see this in the "Advanced System Settings" dialog box, "Computer Name" tab), but System.Environment.MachineName reports this in uppercase. Why is this? This is a real problem for me because, from my tests, PrincipalPermissionAttribute performs case-sensitive comparisons for role names (I map my custom roles to Windows groups and my environment is not a domain). Any tips?

+4
source share
3 answers

Instead, use Dns.GetHostName , which should return it with the correct case (at least on my computer).

+3
source

According to this MSDN article, case insensitive http://msdn.microsoft.com/en-us/library/ms724220(VS.85).aspx

In which scenario does he compare to case?

+1
source

The source for Environment.MachineName for .NET 4.7.1 is here: https://referencesource.microsoft.com/#mscorlib/system/environment.cs,be0b5c103d248dce

It p / calls GetComputerName , as shown here: https://referencesource.microsoft.com/#mscorlib/microsoft/win32/win32native.cs,0c7d7f4f83d4ddd0

Here is the GetComputerName function: https://msdn.microsoft.com/en-us/library/windows/desktop/ms724295(v=vs.85).aspx , which states:

GetComputerName receives only the NetBIOS name of the local computer. To get the DNS host name, DNS domain name, or fully qualified DNS, call the GetComputerNameEx function.

MSDN for computer names, https://msdn.microsoft.com/en-us/library/ms724220(VS.85).aspx , states:

NetBIOS names consist of 15 bytes of OEM characters, including letters, numbers, hyphens, and periods. Some characters are character set specific. NetBIOS names are usually represented in the OEM character set. The OEM character set is locale dependent. Some OEM character sets represent specific characters as two bytes. NetBIOS names, by convention, are represented in uppercase , where the lowercase to uppercase translation algorithm is a set of OEM characters dependent.

So, NetBIOS names are System.Environment.MachineName by convention, and System.Environment.MachineName returns the NetBIOS name of the system.

+1
source

Source: https://habr.com/ru/post/1332601/


All Articles