2

I'm trying to develop a modification to the branding for all MySites in a farm.

Part of my requirements are to display additional information about the user's MySite - not the logged in user, the user whose page you're on.

Is there a way based on the current context of which MySite you are in to detect whose MySite it is?

I thought it would be SPSite.Owner but that doesn't appear to be correct for non-Admins.

1 Answer 1

4

You would need to run the code block as the system account. The safest way to do that is by using the SPUserToken for the system account. Here is an example:

public static string GetSiteOwner(string siteUrl)
{
    var systemToken = SPUserToken.SystemAccount;
    using (var site = new SPSite(siteUrl, systemToken))
    {
        return site.Owner.LoginName;
    }
}
1
  • Since you are already in the context of the site, you can pass in the ID of the site instead of the URL. Commented Dec 5, 2013 at 20:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.