Search code examples
asp.netasp.net-identityasp.net-identity-2asp.net-identity-3

How can the Identity.GetUserId() be made to return a Guid instead of a string?


I am using ASP.Net Identity 2 but soon hope to change to Identity 3 when it becomes more stable (anyone know when that might be?). Here's a sample of my code:

content.ModifiedBy = User.Identity.GetUserId();

The Content table stores ModifedBy as a UNIQUEIDENTIFIER and the Content object assigns a datatype of Guid to ModifiedBy

When I look at the signature for GetUserId() it returns a string.

So how can I take the users UserId and put it into the ModifiedBy which is a Guid?


Solution

  • A guid can take a string as a constructor

    content.ModifiedBy = new Guid( User.Identity.GetUserId());