Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/275.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#Sharepoint获取当前用户的运行代码_C#_Wcf_Sharepoint - Fatal编程技术网

C#Sharepoint获取当前用户的运行代码

C#Sharepoint获取当前用户的运行代码,c#,wcf,sharepoint,C#,Wcf,Sharepoint,我有教程中的代码,代码运行在域\AppPoolAccount下的WCF服务上 但代码除了拒绝访问外,如何确定用户 using (SPSite site = new SPSite("http://portal.local")) { SPServiceContext serviceContext = SPServiceContext.GetContext(site); UserProfileManager u

我有教程中的代码,代码运行在域\AppPoolAccount下的WCF服务上

但代码除了拒绝访问外,如何确定用户

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();


            }
使用(SPSite站点=新SPSite(“http://portal.local"))
{
SPServiceContext serviceContext=SPServiceContext.GetContext(站点);
UserProfileManager userProfileMgr=新的UserProfileManager(serviceContext);
ProfilePropertyManager profilePropMgr=新用户ProfileConfigManager(serviceContext);
//检索“UserProfile”配置文件子类型的所有属性,
//并检索特定用户的属性值。
ProfileSubtyPropertyManager SubtyPropMgr=profilePropMgr.GetProfileSubtyProperties(“UserProfile”);
UserProfile UserProfile=userProfileMgr.GetUserProfile(accountName);
IEnumerator UserProfileSubjectProperties=SubsubjectPropMgr.GetEnumerator();
while(userProfileSubjectProperties.MoveNext())
{
string propName=UserProfileSubjectProperties.Current.Name;
ProfileValueCollectionBase values=userProfile.GetProfileValueCollection(propName);
如果(values.Count>0)
{
//处理多值属性。
foreach(值中的var值)
{
Console.WriteLine(propName+“:“+value.ToString());
}
}
其他的
{
Console.WriteLine(propName+“:”);
}
}
WriteLine(“按Enter键更改值”);
Console.Read();
//更改单值用户属性的值。
userProfile[PropertyConstants.Department].Value=“SDDDD”;
Commit();
}
如何确定用户?

用于确定当前用户:

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();


            }
using (var site = new SPSite(siteUrl))
{
    using (var web = site.OpenWeb())
    {
        var currentUser = web.CurrentUser;
        //..

    }
}

currentUser为null,是否表示匿名?