Separate User name from domain for Logged in User

If you use the LOGON_USER ServerVariable, or User.Identity, to get the logged in user name, then you’ll know that you get it in the following form:
DOMAIN\USERNAME

To get these separately, do something like this:

Dim USERNAME As String = UCase(Request.ServerVariables("LOGON_USER")) lblIdentity.Text = USERNAME.Substring(USERNAME.LastIndexOfAny("\") + 1)

and

lblDomain.Text=USERNAME.Substring(0, USERNAME.IndexOf("\"))

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>