开发者

c# on .net 3.5 SP1 System.Security.Principal.WindowsIdentity.GetCurrent().Name returns names in different order? [Closed - configruation error]

开发者 https://www.devze.com 2022-12-16 20:08 出处:网络
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:

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;
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号