How can I get the connected user name of the windows in the web application?

JERONIMO Edevaldo 40 Reputation points
2024-01-28T20:54:29.2333333+00:00

How can I get the connected user name of the windows in the web application? I tried to use these 03 examples below but didint work when i publish the application in the web server, only work fine in localhost. Is there one way to use javascript? '====Example 01 Dim IdUser = Environment.UserName Dim UserDominio = Environment.UserDomainName Me.IdUser.Text = Environment.UserName '====Example 02 Dim IdUser = Right(User.Identity.Name, InStr(User.Identity.Name, "")) 'Dim UserDominio = Left(User.Identity.Name, InStr(User.Identity.Name, "") - 1) 'Me.IdUser.Text = Right(User.Identity.Name, InStr(User.Identity.Name, "")) '====Example 03 Dim IdUser = Right(System.Security.Principal.WindowsIdentity.GetCurrent.Name.ToString, InStr(System.Security.Principal.WindowsIdentity.GetCurrent.Name.ToString, "")) Dim UserDominio = Left(System.Security.Principal.WindowsIdentity.GetCurrent.Name.ToString, InStr(System.Security.Principal.WindowsIdentity.GetCurrent.Name.ToString, "") - 1) Me.IdUser.Text = Right(System.Security.Principal.WindowsIdentity.GetCurrent.Name.ToString, InStr(System.Security.Principal.WindowsIdentity.GetCurrent.Name.ToString, ""))

Internet Information Services
Windows Server
Windows Server
A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.
11,707 questions
{count} votes

Accepted answer
  1. XuDong Peng-MSFT 8,096 Reputation points Microsoft Vendor
    2024-01-30T09:31:50.68+00:00

    Hi @JERONIMO Edevaldo,

    I tried to use these 03 examples below but didint work when i publish the application in the web server, only work fine in localhost. Is there one way to use javascript?

    Did you mean that these code work fine in Visual studio, but not working after published the application in IIS? If this is the case, you have to check the authentication configuration in IIS as mentioned by Lex Li, otherwise you will get the error code(401.2):

    User's image User's image

    If I misunderstand anything, please let me know.

    Best regards,

    Xudong Peng


    If the answer is the right solution, please click "Accept Answer" and kindly upvote. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful