3,245
社区成员




PSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite site = new SPSite("http://mosscn"))
{
using (SPWeb web = site.OpenWeb())
{
web.AllowUnsafeUpdates = true;
ServerContext context = ServerContext.GetContext(site);
UserProfileManager profileManager = new UserProfileManager(context);
if (profileManager.UserExists("mosscn \\username"))
{
.....
SPSite site = null;
SPWeb web = null;
PSecurity.RunWithElevatedPrivileges(delegate()
{
site = new SPSite("http://mosscn");
web = site.OpenWeb();
}); //RunWithElevatedPrivileges 结束。
web.AllowUnsafeUpdates = true;
ServerContext context = ServerContext.GetContext(site);
UserProfileManager profileManager = new UserProfileManager(context);
if (profileManager.UserExists("mosscn \\username"))
{
.....
if( web != null )
{
web.Dispose();
}
if( site!= null )
{
site.Dispose();
}