-1

I have a welcome head

<h2>welcome</h2>

But I pretend get welcome to the NT logged user

this

<h2>Welcome <%response.write request.servervariables("LOGON_USER")%></h2>

gives me the DOMAIN\USER how I can only show the user? I don't want the domain appears in the text.

EDITED:

I edit this post to not create a new one. I try google but can't find any help I'm getting the correct NT-Logged user. However could I get the name of the nt-user... the corresponding one? Example: Mine NT-User is KFHM. but my name in windows is KikoFHM. At the moment I'm getting the KFHM but how to get the KikoFHM?

KikoFHM
  • 122
  • 14

1 Answers1

2

Just use Split() to separate the Domain from the Username, it uses the \ as a delimiter creating an Array with two elements, to get just the Username call the second element.

Dim username

username = Split(Request.Servervariables("LOGON_USER"), "\")(1)

This is a quick and dirty approach you can expand it and check for the \ beforehand to avoid errors, something like

Dim cred, domain, username,
cred = Request.ServerVariables("LOGON_USER") & ""
If InStr(1, cred, "\") > 0 Then
  cred = Split(cred, "\")
  domain = cred(0)
  username = cred(1)
End If

If you not interested in structuring your code at all you can always use this quick and dirty piece of code;

<%= Split(Request.ServerVariables("LOGON_USER") & "", "\")(1) %>
Community
  • 1
  • 1
user692942
  • 16,398
  • 7
  • 76
  • 175
  • sry I add this `` but gives me error... sry for be noob @Lankymart – KikoFHM Oct 27 '15 at 14:08
  • @KikoFHM If this is Classic ASP you can't do syntax like `<% Dim username = .... %>` it won't work, you need to break the `Dim username` on to a separate line or use this little hack `Dim username : username = Split(request.servervariables("LOGON_USER"), "\") (1)%>`. – user692942 Oct 27 '15 at 14:27
  • @KikoFHM If you want the quickest dirtiest way of doing this just use `

    Welcome <%= Split(Request.Servervariables("LOGON_USER") & "", "\")(1) %>

    `
    – user692942 Oct 27 '15 at 14:29
  • 1
    The quick and the dirty! +1! ;o) – Paul Oct 28 '15 at 12:10
  • @Lankymart you help me before maybe you can help me now again... please see the edited post. yhanks – KikoFHM Oct 29 '15 at 14:27
  • @KikoFHM You should really post a new question or Google, rather then modifying this one. – user692942 Oct 29 '15 at 14:34