Users Pricing

forum

home / developersection / forums / cast the value returned from user.identity.getuserid() to make it a guid

cast the value returned from User.Identity.GetUserId() to make it a GUID

Mark Devid 3984 14 Nov 2014

I created the following class:

public class Config
{
    public Guid UserId { get; set; }
    public string AdminJSON { get; set; }
    public string UserJSON { get; set; }
}

When I query the data I am using:

Config config = await db.Configs.FindAsync(User.Identity.GetUserId());

Is this the correct way to do the find. It seems that User.Identity.GetUserId() returns a string. Should I be casting this to return a GUID.

I also have another problem with this:

UserId = User.Identity.GetUserId()  

This also fails. I tried to do a cast by adding (Guid) before the User.Identity.GetUserId() however this gives a message saying Error 1 Cannot convert type 'string' to 'System.Guid'

It errors out as it cannot


Mark Devid

Other


1 Answers

Markdown for AI

A clean, structured version of this page for AI assistants and LLMs.

Open .md