Web and Environment Variables
-
In a simple web application I have:
TryUserName = Environment.GetEnvironmentVariable("UserName");
LogonServer = Environment.GetEnvironmentVariable("LogonServer");
YourDomainName = Environment.GetEnvironmentVariable("UserDomainName");During development I have a VPN open to the server which is called NZ-SP-AP1. On my home machine set gives me:- Username = Ormond No LogonServer or UserDomainName. On the server, logged in as Administrator, set gives me:- Username = Administrator LogonServer = \\NZ-SP-DC1 (correct) No UserDomainName. When I open the web page on the server with the variables in a textbox, I get:- TryUserName = NZ-SP-AP1$ LogonServer is blank. UserDomainName is blank. Does anyone know where it gets these values, particularly the Username?
-
In a simple web application I have:
TryUserName = Environment.GetEnvironmentVariable("UserName");
LogonServer = Environment.GetEnvironmentVariable("LogonServer");
YourDomainName = Environment.GetEnvironmentVariable("UserDomainName");During development I have a VPN open to the server which is called NZ-SP-AP1. On my home machine set gives me:- Username = Ormond No LogonServer or UserDomainName. On the server, logged in as Administrator, set gives me:- Username = Administrator LogonServer = \\NZ-SP-DC1 (correct) No UserDomainName. When I open the web page on the server with the variables in a textbox, I get:- TryUserName = NZ-SP-AP1$ LogonServer is blank. UserDomainName is blank. Does anyone know where it gets these values, particularly the Username?
It gets the values from the environment settings of the current user space. See Environment.GetEnvironmentVariable Method (System) | Microsoft Docs[^] for a description. But note that since this is C# code it will run on the server so the details will be for the server account that runs the website.
-
In a simple web application I have:
TryUserName = Environment.GetEnvironmentVariable("UserName");
LogonServer = Environment.GetEnvironmentVariable("LogonServer");
YourDomainName = Environment.GetEnvironmentVariable("UserDomainName");During development I have a VPN open to the server which is called NZ-SP-AP1. On my home machine set gives me:- Username = Ormond No LogonServer or UserDomainName. On the server, logged in as Administrator, set gives me:- Username = Administrator LogonServer = \\NZ-SP-DC1 (correct) No UserDomainName. When I open the web page on the server with the variables in a textbox, I get:- TryUserName = NZ-SP-AP1$ LogonServer is blank. UserDomainName is blank. Does anyone know where it gets these values, particularly the Username?
Anticipating your next question: no, there is no way for a website to obtain these details from a user's computer. If there were, that would be a security vulnerability. If this is an intranet site, and your users are all part of the same domain/forest as the web server, you might be able to use Windows authentication on your site. Depending on their browser settings, they would either automatically log in as themselves, or have to enter their Windows username and password to log in. Windows Authentication <windowsAuthentication> | Microsoft Docs[^] If this is an internet site, where your users are not part of your domain, then you cannot obtain any information about their user account.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
In a simple web application I have:
TryUserName = Environment.GetEnvironmentVariable("UserName");
LogonServer = Environment.GetEnvironmentVariable("LogonServer");
YourDomainName = Environment.GetEnvironmentVariable("UserDomainName");During development I have a VPN open to the server which is called NZ-SP-AP1. On my home machine set gives me:- Username = Ormond No LogonServer or UserDomainName. On the server, logged in as Administrator, set gives me:- Username = Administrator LogonServer = \\NZ-SP-DC1 (correct) No UserDomainName. When I open the web page on the server with the variables in a textbox, I get:- TryUserName = NZ-SP-AP1$ LogonServer is blank. UserDomainName is blank. Does anyone know where it gets these values, particularly the Username?
ASP.NET code runs entirely on the server, never on the client or in the browser. Your code is running on the web server under a service account, so the user information you get back is going to be for the user account the web server is running your code under. No, there is no way to get the code your wrote to work on the client machine.
Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
Dave Kreskowiak