Whose site do I find? (Program)

I am creating a web part to host Sharepoint My Sites. I need to get SPUser whose site My website is on. I'm just using now

Request.QueryString["accountname"] 

but this will not work on my own site, and I'm not sure that it will work all the time.

+6
source share
3 answers

When Request.QueryString["accountname"] empty, the user must be in his own mysite so that you can look at SPContext.Current.Web.CurrentUser to get the user.

+2
source

here is another approach using UserProfile (Microsoft.Office.Server.UserProfiles)

 var profileLoader = Microsoft.SharePoint.Portal.WebControls.ProfilePropertyLoader.FindLoader(HttpContext.Current.Handler as Page); var userProfile = profileLoader.ProfileLoaded; var loginName = userProfile["AccountName"]; 

And then just get your SPUser from SPContext.Current.Web;

+2
source

Another possible way to do this is to use the SPSite Owner property. This will give you the SPUser object, which is usually preferred. This property corresponds to the "Site Owner" property, which can be configured in the Central Administration in the "Change Site Collection Administrator" section. However, keep in mind that since this can be configured, it should not be trusted as the absolute source of knowledge whose site you have on my site.

+1
source

Source: https://habr.com/ru/post/899098/


All Articles