简体   繁体   English

启动.NET应用程序时由什么决定您的USERPROFILE环境变量

[英]What determines your USERPROFILE Environment Variable when launching a .NET app

I have a .net/C# application when launched on a test server running VMWARE / Windows Server 2008, receives a USERPROFILE Environment Variable pointing to C:\\windows\\system32\\config\\systemprofile, but other applications seemingly built in a similar fashion inhert the correct value of C:\\Users\\{username}. 在运行VMWARE / Windows Server 2008的测试服务器上启动时,我有一个.net / C#应用程序,收到指向C:\\ windows \\ system32 \\ config \\ systemprofile的USERPROFILE环境变量,但其他应用程序似乎以类似的方式继承了C:\\ Users \\ {username}的正确值。

A slight twist - the application receives the correct value when run locally on my development machine. 稍作改动-在我的开发机器上本地运行时,应用程序会收到正确的值。 So I'm thinking this is a profile/registry issue with some combination of setting in my app. 因此,我认为这是个人资料/注册表问题,其中包含应用程序中设置的某种组合。

The issues is manifested when you attempt to open an OpenFileDialog or similar. 当您尝试打开OpenFileDialog或类似文件时,问题就显现出来了。 You get the exception "Location is not available: C:\\Windows\\system32\\config\\systemprofile\\Desktop refers to a location that is unavailable..." 您会收到异常“位置不可用:C:\\ Windows \\ system32 \\ config \\ systemprofile \\ Desktop引用的位置不可用...”

Any ideas? 有任何想法吗?

UPDATE: The application is WPF running web services against IIS via WCF. 更新:该应用程序是WPF通过WCF针对IIS运行Web服务。 Locally in development I am using IISExpress. 在本地开发中,我正在使用IISExpress。 I've found that after touching the WCF services in the client, the application inherits the APPDATA and USERPROFILE of the IIS AppPool the services are running under. 我发现在触摸客户端中的WCF服务后,该应用程序继承了服务在其下运行的IIS AppPool的APPDATA和USERPROFILE。 If I adjust the AppPool values to use my user account instead of ApplicationPoolDefault and set LoadUserProfile = true - things work. 如果我调整AppPool值以使用我的用户帐户而不是ApplicationPoolDefault并设置LoadUserProfile = true-一切正常。 Obviously this is a bad thing. 显然,这是一件坏事。 As an alternative, I cache off the environment variables when the WPF app runs, and after it initially connects to WCF, I reset the variables. 作为替代方案,我在WPF应用程序运行时将环境变量缓存起来,并且在它最初连接到WCF之后,我会重置这些变量。 This appears to get around the issue but I'd like to solve it a better way but I have no idea what is influencing this behavior in WCF and my IIS Services. 这似乎可以解决问题,但是我想以更好的方式解决它,但我不知道什么因素在WCF和IIS服务中影响了此行为。

It might have to deal with what account the web app is running under in IIS. 它可能必须处理Web应用程序在IIS中运行的帐户。 You can change it from the default "Network Service" account to an actual user account. 您可以将其从默认的“网络服务”帐户更改为实际的用户帐户。

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

相关问题 什么决定了针对“AnyCpu”平台的 .NET 应用程序是以 32 位还是 64 位运行的? - What determines if a .NET app that targets the "AnyCpu" platform runs at 32 or 64 bits? 当 ASP.Net 收到带有 DateTime 属性的已发布 model 时,什么决定了 DateTime.Kind? - What determines the DateTime.Kind when ASP.Net receives a posted model with a DateTime property? 在Debian上启动.NET Core应用程序时出现分段错误 - Segmentation fault when launching .NET Core app on Debian 固定到任务栏时,应用程序名称由什么决定? - What determines the application name when pinned to taskbar? ".NET Core 控制台应用程序和 aspnetcore_environment 变量" - .NET Core console app and aspnetcore_environment variable 是什么决定了C#程序中的.NET日期格式? - what determines .NET date formats in C# program? .net内存使用情况,决定私有字节大小的因素 - .net memory usage, what determines private byte size 应用程序启动时ValidationError上的XamlParseException - XamlParseException on ValidationError when App launching .NET MAUI 环境变量 - .NET MAUI Environment variable 在启动显示浏览器的进程后停止/终止 .net 核心 web 应用程序进程的正确方法是什么 - What is the proper way to stop/kill a .net core web app process after launching a process to display the browser
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM