我在谁的“我的网站”上? (以编程方式)
我正在构建一个 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
当
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 inSPContext.Current.Web.CurrentUser
to get the user.这是使用 UserProfile (Microsoft.Office.Server.UserProfiles) 的另一种方法
,然后从 SPContext.Current.Web 获取 SPUser;
here is another approach using UserProfile (Microsoft.Office.Server.UserProfiles)
And then just get your SPUser from SPContext.Current.Web;
另一种可能的方法是使用
SPSite
的Owner
属性。这将为您提供一个通常更可取的SPUser
对象。此属性与“网站所有者”属性相关,该属性可以在管理中心的“更改网站集管理员”下进行配置。但请注意,由于这是可以配置的,因此不能将其视为了解您所在的“我的网站”的绝对来源。Another possible way of doing this is to use the
SPSite
'sOwner
property. This will give you anSPUser
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.