Last post Jun 22, 2017 08:45 AM by Eric Du
Jun 21, 2017 03:22 PM|Hariharans87|LINK
I am new to asp.net membership security. I have multiple project in same solution. I have created one new ASP.Net Web API project. This project is using other project classes.
In that classes, they are referring the logged in user for updating createdby field in the database table.
If i create any record from newly created Web API project, it always storing 00000000-0000-0000-0000-000000000000 value.
I am having one user account. I want to set this user as logged in user in my Web API project.
Could you please tell me how to set particular user as logged in user?
Jun 22, 2017 02:52 AM|JBetancourt|LINK
are you by any chance using
var id = new Guid()
that returns 000-000... the proper way to generate a guid is
var id = Guid.NewGuid()
Jun 22, 2017 08:45 AM|Eric Du|LINK
According to your description, as far as I know, you could refer to the following code to assign a specify user:
public override void OnAuthorization(HttpActionContext actionContext)
var identity = new ClaimsIdentity();
identity.AddClaim(new Claim(System.Security.Claims.ClaimTypes.Name, "username1"));
identity.AddClaim(new Claim(System.Security.Claims.ClaimTypes.NameIdentifier, "1234"));
actionContext.ControllerContext.RequestContext.Principal = new ClaimsPrincipal(identity);
Also please refer this document to create a GUID:
Guid.NewGuid Method ():