locked
WCF and Custom Profile Provider RRS feed

  • Question

  • User1186064815 posted

    I have a custom SQL profile provider and I would to access the users profile properties in a WCF web service.  I have the profile provider settings added to the web.config and I have successfully implemented a custom membership and role provider within the same WCF web service.  When i try to call System.Web.HttpContext.Current.Profile.GetPropertyValue("MyPropertyName").ToString() it returns null because the current user is null.  I have <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" /> in my web.config and  [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] on my WCF service.

    Wednesday, March 13, 2013 3:24 PM

Answers

  • User1186064815 posted

    Here's the answer:

     

    public string GetData(int value)

    {

    IIdentity currentUser = ServiceSecurityContext.Current.PrimaryIdentity;

    if (Roles.IsUserInRole(currentUser.Name, "Developer"))

    {

    CDIMembershipUser u = (CDIMembershipUser)Membership.GetUser(currentUser.Name);

    ProfileBase pb = ProfileBase.Create(currentUser.Name, currentUser.IsAuthenticated);

    String accountNumber = pb.GetPropertyValue("AccountNumber").ToString();

    return string.Format("Hello {0}. You entered: {1}.", u.FirstName + " " + u.LastName + "(" + accountNumber + ")", value);

    }

    else

    {

    return "Access denied";

    }

    }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, March 19, 2013 12:22 PM

All replies