[英]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.