Adding roles from a DB Table
Can anyone expalin me how to dynamically ger the Role from a DB table instead of hard coding it in the code.
ClaimsIdentity outputIdentity = new ClaimsIdentity(开发者_JAVA技巧);
outputIdentity.Claims.Add(new Claim(System.IdentityModel.Claims.ClaimTypes.Name, principal.Identity.Name));
outputIdentity.Claims.Add(new Claim(ClaimTypes.Role, "Manager"));
outputIdentity.Claims.Add(new Claim(ClaimTypes.Country, HttpUtilities.GetProgramIdentifierFromUrl()));
return outputIdentity;
How are you storing your Roles? I presume it is something along the lines of:
Create Table Roles
(
RoleId int identity(1,1) Not Null,
RoleName varchar(50) not null
)
Why don't you just query the Database to fetch the RoleId and then use the result of the query in your update.
Wouldn't a user have selected the Role somewhere in this process? Can't you grab the ID or RoleName for their initial selection?
精彩评论