문제

I am building a web part to put on Sharepoint My Sites. I need to get the SPUser whose My Site the web part is on. Currently I simply use

Request.QueryString["accountname"]

but this will not work on my own My Site, and I am not sure it will work all the time either.

도움이 되었습니까?

해결책

When Request.QueryString["accountname"] is empty the user should be on its own mysite so then you could look in SPContext.Current.Web.CurrentUser to get the user.

다른 팁

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;

Another possible way of doing this is to use the SPSite's Owner property. This will give you an SPUser object which is usually preferable. This property correlates to the "Site Owner" property which can be configured in Central Admin under "Change Site Collection Administrator". However be aware that since this can be configured, it is not to be trusted as an absolute source of knowing whose my site you're on.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top