Re: How can I get the domain name and username?

cherry_adriano_at_yahoo.com
Date: 12/16/03


Date: Tue, 16 Dec 2003 00:48:19 -0800

Sir Chris,
System.Web.HttpContext.User.Identity.Name returns
domain\username where domain is my computer name and
username as ASPNET. Do you know how can I get network
logon name(username) and domain used in logging on to
Operating System?

There is a way to get the network logon name using vb6 .
See VB6 script below. How can I get this in VB.net Thanks
=)

Private Declare Function w32_WNetGetUser Lib "mpr.dll"
Alias "WNetGetUserA" (ByVal lpszLocalName As String, ByVal
lpszUserName As String, lpcchBuffer As Long) As Long
Private Sub Form_Load()
    'KPD-Team 1998
    'URL: http://www.allapi.net/
    'E-Mail: KPDTeam@Allapi.net
    Dim lpUserName As String, lpnLength As Long, lResult
As Long
    'Create a buffer
    lpUserName = String(256, Chr$(0))
    'Get the network user
    lResult = w32_WNetGetUser(vbNullString, lpUserName,
256)
    If lResult = 0 Then
        lpUserName = Left$(lpUserName, InStr(1,
lpUserName, Chr$(0)) - 1)
        MsgBox "The user's Network Logon Name is " +
lpUserName + ".", vbInformation + vbOKOnly, App.Title
    Else
        MsgBox "No user found !", vbExclamation +
vbOKOnly, App.Title
    End If
End Sub
>-----Original Message-----
>System.Web.HttpContext.User.Identity.Name will return a
string in the form
>domain\userName.
>
>--
>Chris Jackson
>Software Engineer
>Microsoft MVP - Windows Client
>Windows XP Associate Expert
>--
>More people read the newsgroups than read my email.
>Reply to the newsgroup for a faster response.
>(Control-G using Outlook Express)
>--
>
>"Cherry Adriano" <cherry_adriano@yahoo.com> wrote in
message
>news:095801c3bfb7$eebeade0$a101280a@phx.gbl...
>> I'm new with .net programming....so pls bear with me.
May
>> I ask how can I get the domain name and username of user
>> who is trying access my web application.
>
>
>.
>



Relevant Pages

  • Re: Password access for folders over network
    ... the network logon always uses the currently logged on user ... but you *can* get it to prompt for the password. ... username, ...
    (microsoft.public.windowsxp.security_admin)
  • Re: Cannot logon to XP after changing network settings
    ... it no longer lets me logon. ... Make sure your username and domain are correct" ... the network settings from a business network to a home network. ... What happen if you logged into safe Mode and create a local account. ...
    (microsoft.public.windowsxp.help_and_support)
  • cached credentials and shared resources access
    ... goes away he can logon and work in domain with cached credentials. ... for a logon and, entering user and pwd of the cached logon, it answers ... Username already used. ... It's a very fast reply, without querying network, so I think it's ...
    (microsoft.public.windowsxp.network_web)
  • Re: Finding User Id
    ... > Several variations of code to return username at this google search result. ... these return the logon name ... Function fOSUserNameAs String ... Dim lngLen As Long, lngX As Long ...
    (microsoft.public.excel.misc)
  • RE: Windows2000 Security events
    ... Someone is testing / using Kerberos on your network without your ... frame...same username and domain. ... Special privileges assigned to new logon: ...
    (Focus-Microsoft)