In an aspx page I get the Windows username with the function Request.LogonUserIdentity.Name. This function returns a string in the format ‘domain\user’.
Is there some function to only get the username, without resorting to the IndexOf and Substring, like this?
public static string StripDomain(string username) { int pos = username.IndexOf('\\'); return pos != -1 ? username.Substring(pos + 1) : username; }
I don’t believe so. I have got the username using these methods before-
or