Question: I need to get the userId of the logged in user in ASP.net, I can use 

```
System.Web.HttpContext.Current.User.Identity.Name

```

to get the name, but how do I get the userID?

I tried (GUID) and Membership.GetUser as I found, but none seem to work.

Answer: 
This should work for you

```
MembershipUser user = Membership.GetUser(HttpContext.Current.User.Identity.Name);
string userID = user.ProviderUserKey.ToString();

```

**Edit:**

You need to make sure you import the System.Web.Security class to use the MembershipUser class. In VB.Net you can do that like this:

**HTML**

```
<%@ Import Namespace="System.Web.Security" %>

```

**Code Behind**

```
using System.Web.Security;

```
`Dim mu As System.Web.Security.MembershipUser = System.Web.Security.Membership.GetUser()`

`Dim strUsrId As String = mu.ProviderUserKey.ToString()`

Hope this helps.