Sharepoint获取用户信息
问题描述:
我有MOSS服务器和用户授权正在通过AD。Sharepoint获取用户信息
我想programmaticaly获取一些当前的用户信息,如电子邮件,phome号码。
我提出了以下步骤: 1)创建具有DLL [组件:AllowPartiallyTrustedCallers] 2)我有类PhoneBookCL继承System.Web.UI.WebControls.WebParts.WebPart
我尝试覆盖的CreateChildControls () 供测试用;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.Office.Server;
using Microsoft.Office.Server.UserProfiles;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.Portal;
public class PhoneBookCL : WebPart
{
SPUser currentUser = null;
protected override void CreateChildControls()
{
try
{
SPWeb web = SPControl.GetContextWeb(Context);
currentUser = web.CurrentUser;
}
catch (Exception exp) { value = exp.Message; }
}
}
3)分配强名称到DLL,然后添加到的SafeControl web.config中:
4)DLL - >到\ Bin目录,将此添加到的WebPart SP的WebParts收集, 加入web部件到新页面。
刷新进入异常的页面:意外的异常。
如果我删除
"SPWeb web = SPControl.GetContextWeb(Context);
currentUser = web.CurrentUser;"
那么所有的伟大工程。
我可以创建标签并更改其Text属性和其他东西。 另外我试图从Microsoft.SharePoint.WebControls.WebPart继承,它实际上继承了UI ... WebPart,所以结果是一样的。
也许有一些安全问题?
答
当您将dll部署到bin时会发生此问题。我假设你的web.config的信任等级为WSS_minimal。最小信任将不允许访问对象模型。
因此,您有以下选择:
- 部署使用自定义代码访问安全WSP的web部件。这有点乏味。
- 将web.config中的信任级别更改为Full。
- 将dll部署到GAC。
从最佳实践的角度来看,使用自定义代码访问安全性将dll部署到bin将是最佳选择。但是如果你没有安全限制,你可以考虑部署到GAC来简化操作。
参考:http://msdn.microsoft.com/en-us/library/ee909485%28office.12%29.aspx
问候, 法伊兹
谢谢! 其实只是找到自己的答案 http://msdn.microsoft.com/en-us/library/dd583158%28office.11%29.aspx。 无论如何,你是对的! – Artru 2010-05-24 11:40:58
没有足够的声望来添加plus。 – Artru 2010-05-24 11:43:27