i am working on a windows forms .net 3.5 project in c# and the project uses the following line to get the current user:
Created_By = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
On one box the result is hostname\username but on 开发者_JAVA百科my box the result is username\hostname. Both boxes run Windows 7 Ultimate.
I searched on google but did not find any explanation.
Any explanation or suggestion is apprectiated,
Dawit
According to MSDN the Name
property should return the user name:
The logon name is in the form DOMAIN\USERNAME.
Is the result produced by the same assembly just on a different machine? And is this machine part of a domain?
Although I have no explanation for the behavior that you are experiencing, you could try the following workaround:
string username = Environment.UserDomainName + "\\" + Environment.UserName;
精彩评论