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.

有帮助吗?

解决方案

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:

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top