To access a user's profile within an anonymous accessable portal, you can use the code snippet below:
SPSecurity.RunWithElevatedPrivileges(delegate(){ SPSite sc = new SPSite(SPContext.Current.Site.ID); ServerContext context = ServerContext.GetContext(sc); HttpContext currentContext = HttpContext.Current; HttpContext.Current = null; UserProfileManager profileManager = new UserProfileManager(context); UserProfile user = profileManager.GetUserProfile("DOMAIN\userName"); writer.Write(user.PersonalUrl); HttpContext.Current = currentContext;});
The important part of this code snippet is setting null as value to the current HTTP context while reading from the user profile store. Without this action, you'll get access errors and not be able to reach the profile store.