asp.netweb-servicesasp.net-profiles

Profile access in ASP.NET web services


ASP.NET profile properties are trivially available to the code-behind of an ASPX web page courtesy of the HttpContext.Current.Profile object.

In a .svc web service, how does one bring ProfileCommon and paraphernalia into scope?


Solution

  • In the web.config file is a commented out section controlling whether the profile service is enabled. Enabling it changes the generated code and HttpContext becomes available.

    You don't have the class that descends from ProfileBase to present profile properties as strongly typed properties. This however is hardly a disaster, you just use

      HttpContext.Current.Profile.GetPropertyValue(string propName)
    

    and cast the result.