I have enabled FBA in my site. We are trying to override people picker with this link. We have override people picker method in farm level feature event receiver as suggested in method.

I am trying to call a service for getting users in event receiver. For that call I need to pass SecurityToken. I have stored user token in session on login page. Below is my code sample to get users:

 SecurityToken token = (SecurityToken)HttpContext.Current.Session["ServiceToken"];

                var service = _serviceGateway.GetServiceFactory<IGSRoleProvider>(token, _serviceGateway.RoleProviderEndpoint().Uri);
                var claims = string.Empty;

                //Building a claims string
                string key = companyid;
                string myValue = string.Empty;
                foreach (var claim in identity.Claims)
                    claims += claim + "\\n\\n";
                    if (claim.ClaimType == "http://mysite/claims/companyid")
                        key = claim.Value;

                userSet = service.FindUsers(prefix, Convert.ToInt32(key));
                return userSet.Tables[0];

The issue I am facing is HttpContext.Current.Session is null in event receiver. So is there any other way we can get SecurityToken in event receiver?


You can use Farm level property bag as Session is not available in event receiver (or I should say claim provider event receiver). Below is code sample I use in my code:

SPFarm farmObject = SPFarm.Local;
if (farmObject.Properties != null && farmObject.Properties.Count > 0)
   if (!farmObject.Properties.ContainsKey(loginusername))
      farmObject.Properties[loginusername] = key;
      farmObject.Properties[loginusername + "login_token"] = ServiceToken;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.