I assume this is a web application question??? It seems to work in development because the development machine is the client and the server. Once deployed the users do not login and run the web application from the server.
How can I get UserProfile name in C# code on Azure Windows server
Within a C# app I need to get the current user name for an Azure Windows VM (2019). I need the path for the current user, like - c:\Users\my_user_name\Desktop.
Something similar to %userprofile%
The following works in development on a Windows 10 machine but not on an Azure Windows Virtual Machine.
Environment.UserName
Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments))
Environment.GetFolderPath(Environment.SpecialFolder.Desktop))
1 additional answer
Sort by: Most helpful
-
Bruce (SqlWork.com) 66,226 Reputation points
2022-03-31T15:21:50.037+00:00 web applications are normally run as service or hosted by IIS which is a service. Applications running as a service do not load a user profile, so you can not get user profile properties.
if you Remote Desktop to the server and run the app, it will you your login profile.
note: as suggested, the profile is the account running the application.