tags:

views:

21

answers:

1

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();
        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;
+1  A: 

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?

Barry
Sorry Barry I asked the question wrong. Can I add my own members in claimtypes, current the claimtypes class has the following members,AnonymousAuthenticationAuthorizationDecisionCountryDateOfBirthDenyOnlySidDnsEmailGenderGivenNameHashHomePhoneLocalityMobilePhoneNameNameIdentifierOtherPhonePostalCodePPIDRsaSidSpnStateOrProvinceStreetAddressSurnameSystemThumbprintUpnUriWebpageX500DistinguishedNameIs it possible to add a new member. It is a static class and no way to inherit it.
Sunil Ramu
Would this be of any use to you? http://msdn.microsoft.com/en-us/library/ms734687.aspx
Barry
Thanks Barry. I will just go with this. Will send you a sample after some time.
Sunil Ramu
Thanks - I'm sure it will come in handy.
Barry