Thread: Problems accessing logged on user via System.Security

  1. #1
    Registered User
    Join Date
    Apr 2005
    Posts
    11

    Thumbs up Problems accessing logged on user via System.Security

    Hi.

    In a C#/ASP web application, I used

    String username = System.Security.Principal.WindowsIdentity.GetCurre nt().Name;

    to get the username of the user currently logged on to Windows. And this works fine when accessing the webpage if it's on my own computer but when I publish the site and access it from anywhere else, it returns “NT AUTHORITY\NETWORK SERVICE” for the username.

    Is there any way to have this work for people accessing the site from somewhere else as well?

    Thanks,
    Conor.

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    What are you trying to do? Do you want to know the user that is logged into the web-browser, or the user that happens to be logged in on the server, or something else?

    Since the ASP runs on the server, it's kind of hard to figure out anything that happens on the client-side...

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Apr 2005
    Posts
    11
    The username of the user using the site. Preferably the username from his/her machine.

    It's to store information in an SQL database along with the persons username so when they come back, it can automatically be retrieved.

    Conor.

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    I think the most obvious solution is to ask the user to log in - with or without password - and use that to log to the database.

    You can use cookies to store the logged in name and use the cookie to retrieve the name later on.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Registered User
    Join Date
    Apr 2005
    Posts
    11
    Yeah, that was how it was originally set up but then when getting the local user's username worked, it cleaned up the whole process up.

    So there's no way of getting it from a machine logging in over a network / website?

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    I'm quite certain from an ASP you can't trivially access information from the user's machine - my brief search of JavaScript functions didn't reveal any such thing either.

    Another, better google effort found this: http://www.thescripts.com/forum/thread90803.html

    So it sounds like there's no good way to do this.

    --
    Mats
    Last edited by matsp; 11-16-2007 at 07:55 AM.
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. ~ User Input script help~
    By indy in forum C Programming
    Replies: 4
    Last Post: 12-02-2003, 06:01 AM
  2. comparing user input
    By lambs4 in forum C Programming
    Replies: 5
    Last Post: 12-15-2002, 10:28 AM
  3. Need Help with syntax and overall problems!
    By Simon in forum C Programming
    Replies: 1
    Last Post: 09-11-2002, 11:15 PM
  4. Replies: 6
    Last Post: 07-10-2002, 07:45 PM
  5. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM