我有来自教程的代码,代码在DOMAIN \ AppPoolAccount
下的WCF服务上运行但代码除了Access Denied,用户如何确定?
using (SPSite site = new SPSite("http://portal.local"))
{
SPServiceContext serviceContext = SPServiceContext.GetContext(site);
UserProfileManager userProfileMgr = new UserProfileManager(serviceContext);
ProfilePropertyManager profilePropMgr = new UserProfileConfigManager(serviceContext).ProfilePropertyManager;
// Retrieve all properties for the "UserProfile" profile subtype,
// and retrieve the property values for a specific user.
ProfileSubtypePropertyManager subtypePropMgr = profilePropMgr.GetProfileSubtypeProperties("UserProfile");
UserProfile userProfile = userProfileMgr.GetUserProfile(accountName);
IEnumerator<ProfileSubtypeProperty> userProfileSubtypeProperties = subtypePropMgr.GetEnumerator();
while (userProfileSubtypeProperties.MoveNext())
{
string propName = userProfileSubtypeProperties.Current.Name;
ProfileValueCollectionBase values = userProfile.GetProfileValueCollection(propName);
if (values.Count > 0)
{
// Handle multivalue properties.
foreach (var value in values)
{
Console.WriteLine(propName + ": " + value.ToString());
}
}
else
{
Console.WriteLine(propName + ": ");
}
}
Console.WriteLine("Press Enter to change the values.");
Console.Read();
// Change the value of a single-value user property.
userProfile[PropertyConstants.Department].Value = "SDDDD";
userProfile.Commit();
}
如何确定用户?
答案 0 :(得分:0)
使用SPWeb.CurrentUser property确定当前用户:
using (var site = new SPSite(siteUrl))
{
using (var web = site.OpenWeb())
{
var currentUser = web.CurrentUser;
//..
}
}