简体   繁体   English

Environment.UserName 作为 SYSTEM 而不是用户名返回

[英]Environment.UserName returning as SYSTEM rather than User's name

I've been using我一直在用

Environment.UserName

To display the current user's name and it's been working all this time.显示当前用户的名称,并且一直在工作。

However, started working on my project today - Environment.UserName has returned the word "SYSTEM" despite the user name still being the same as it was before.但是,今天开始处理我的项目 - 尽管用户名仍然与以前相同,但Environment.UserName返回了"SYSTEM"一词。

Happened to us too 3 days ago, we were reaching the documents and settings via Environment.UserName (i guess it was a windows update) 3 天前也发生在我们身上,我们通过Environment.UserName文档和设置(我猜这是 Windows 更新)

We solved it by using %USERPROFILE% instead of Environment.UserName in the string.我们通过在字符串中使用 %USERPROFILE% 而不是Environment.UserName来解决它。

 readonly string savedFilesDirectoryPath =
     Environment.ExpandEnvironmentVariables(@"%USERPROFILE%\Documents\OurProjectName");

%USERPROFILE% env var on windows indicates where a user home directory is located in the file system Windows 上的 %USERPROFILE% env var 指示用户主目录在文件系统中的位置

For your exact question tho: I think in build mode your solution will work actually so try that对于您的确切问题:我认为在构建模式下,您的解决方案实际上会起作用,因此请尝试

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Environment.UserName 返回应用程序池名称而不是用户名 - Environment.UserName returning application pool name instead of username Environment.UserName 为同一用户(外壳)提供不同的结果:替代/转换? - Environment.UserName gives different results for same user (casing): alternative/transformation? 我可以使用 Environment.Username 和 MYSQL 来验证登录吗? - Can I use Environment.Username and MYSQL to verify log in? 在 Windows 服务中使用时 Environment.UserName 会返回什么 - What would Environment.UserName return when used in a Windows Service 将app.config值设置为Environment.UserName - Set app.config value to Environment.UserName ASP.NET中的System.Web.HttpContext.Current.User.Identity.Name与System.Environment.UserName的对比 - System.Web.HttpContext.Current.User.Identity.Name Vs System.Environment.UserName in ASP.NET C# 和 MVC 中的 System.Environment.Username 和 User.Identity.Name 有什么区别? - Whats the Difference between System.Environment.Username and User.Identity.Name in C# and MVC? Environment.UserName会在Windows 7,Windows 8.x和Windows 10中返回相同的结果吗? - Will Environment.UserName return the same result in Windows 7, Windows 8.x and Windows 10? .NET MVC视图返回对象名称而不是特定对象 - .NET MVC view returning object name rather than specific object 全名而不是User.Identity.Name中的域ID - Full name rather than the domain id in User.Identity.Name
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM