Question

In Umbraco 4.11 using the default member provider, is it possible to access the profile of a user who is not logged in?

I've added the custom profile properties to the web.config, added the same props on the MemberType in the back office and I'm creating the profile by doing this:

MembershipUser member = System.Web.Security.Membership.CreateUser(username, password, email);
var profile = System.Web.Profile.ProfileBase.Create(member.UserName);
profile["FirstName"] = "John";
profile.Save();

I can get the current logged in users profile by doing this:

var currentUser = umbraco.cms.businesslogic.member.Member.GetCurrentMember();

But how do I get the profile of a user who is not logged in?

eg. I tried:

var profile =  System.Web.Profile.ProfileManager.FindProfilesByUserName(System.Web.Profile.ProfileAuthenticationOption.All, username); 

But this results in a "Specified Method Not Supported" exception.

This will be used in an admin service which performs a periodic sync with an external provider so there will be no user context.

Was it helpful?

Solution

You use ProfileBase.Create() again. Don't worry, it doesn't actually "create" the profile again.

var profile = ProfileBase.Create(username);
string firstName = profile["FirstName"];

For more information, refer to:

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top