6

我正在构建一个 Web 部件以放在 Sharepoint 我的网站上。我需要获取 Web 部件所在的我的网站的 SPUser。目前我只是使用

Request.QueryString["accountname"]

但这在我自己的“我的网站”上不起作用,我也不确定它是否会一直起作用。

4

3 回答 3

2

Request.QueryString["accountname"]为空时,用户应该在自己的 mysite 上,这样您就可以查看SPContext.Current.Web.CurrentUser以获取用户。

于 2011-10-12T07:25:16.523 回答
2

这是使用 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"];

然后从 SPContext.Current.Web 获取您的 SPUser;

于 2013-03-11T13:19:01.530 回答
1

另一种可能的方法是使用SPSite'Owner属性。这会给你一个SPUser通常更可取的对象。此属性与可以在 Central Admin 中的“更改网站集管理员”下配置的“网站所有者”属性相关。但是请注意,由于可以对其进行配置,因此不能将其视为知道您在我的网站上的绝对来源。

于 2015-05-14T00:40:55.043 回答