I posted a question to stackoverflow but I would like to also post here just so it does not get missed. I will update both if an answer is found.
http://stackoverflow.com/questions/22233357/httpcontext-current-profile-null-when-used-as-a-profileservice-and-not-setting-t
I have an ASP.NET application that exposes a profile service. The service is working fine when I have the "properties" tag hard coded into the web.config file. The ProfileProvider GetPropertyValues gets called and I am able to set the values for the properties.
Now we have a requirement to remove all the "properties" from the web.config and place them into a class.
I created a class called "CustomProfile" and inherit from System.Web.Profile.ProfileBase I then removed the "properties" from the web.config and added inherits="CustomProfile". No other code has been modified. Now when I call the service, the ProfileProvider
GetPropertyValues never gets called. After adding Profile_Personlize in the Global.asax I noticed that HttpContext.Current.Profile is always null but if I add the "properties" back into the web.config then the HttpContext.Current.Profile is not null.
I can even add the following in the Profile_Personalize
var userProfile =ProfileBase.Create(user)asCustomProfile;string fullName = userProfile.FullName;
Then this will call the GetPropertyValues from the custom profile provider and will get me the property but of course this will not work for an external service caller.
It's like there is some event / wiring under the hood that sets the HttpContext.Current.Profile but I don't know how to get to that event to manually set the HttpContext.Current.Profile and of course HttpContext.Current.Profile is read only...
EDIT:
When the application_PreRequestHandlerExecute event fires, the HttpContext.Current.Profile is not null. So it is some even after this that is setting the HttpContext.Current.Profile back to null.