我在谁的“我的网站”上? (以编程方式)

发布于 2024-12-09 09:13:54 字数 184 浏览 0 评论 0原文

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

Request.QueryString["accountname"]

但这不适用于我自己的“我的网站”,而且我不确定它是否会一直有效。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

木格 2024-12-16 09:13:54

Request.QueryString["accountname"] 为空时,用户应该位于自己的 mysite 上,因此您可以在 SPContext.Current.Web.CurrentUser 中查找以获取用户。

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.

堇年纸鸢 2024-12-16 09:13:54

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

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;

宁愿没拥抱 2024-12-16 09:13:54

另一种可能的方法是使用 SPSiteOwner 属性。这将为您提供一个通常更可取的 SPUser 对象。此属性与“网站所有者”属性相关,该属性可以在管理中心的“更改网站集管理员”下进行配置。但请注意,由于这是可以配置的,因此不能将其视为了解您所在的“我的网站”的绝对来源。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文