Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Web and Environment Variables

Web and Environment Variables

Scheduled Pinned Locked Moved C#
sharepointsysadminquestionworkspace
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • O Offline
    O Offline
    ormonds
    wrote on last edited by
    #1

    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?

    L R D 3 Replies Last reply
    0
    • O ormonds

      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?

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • O ormonds

        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?

        R Offline
        R Offline
        Richard Deeming
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • O ormonds

          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?

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups