<p>In an aspx page I get the Windows username with the function <code>Request.LogonUserIdentity.Name</code>. This function returns a string in the format "domain\user".</p>

<p>Is there some function to only get the username, without resorting to the <code>IndexOf</code> and <code>Substring</code>, like this?</p>

<pre><code>public static string StripDomain(string username)
{
    int pos = username.IndexOf('\\');
    return pos != -1 ? username.Substring(pos + 1) : username;
}
</code></pre>

I don't believe so. I have got the username using these methods before-
```
```
var user = System.Web.HttpContext.Current.User;   
var name = user.Identity.Name;

var slashIndex = name.IndexOf("\\");
return slashIndex > -1 
    ? name.Substring(slashIndex  + 1)
    : name.Substring(0, name.IndexOf("@"));
```
```
or
```
```
var name = Request.LogonUserIdentity.Name;

var slashIndex = name.IndexOf("\\");
return slashIndex > -1 
    ? name.Substring(slashIndex  + 1)
    : name.Substring(0, name.IndexOf("@"));
```
```