Pages

Search This Blog

Sunday, January 5, 2014

All users are logged in as System Account

There is a very strange problem we were facing in which any contributor or user when logged in into SharePoint 2010 site then it started showing him / her as sharepoint\system account. This is very strange and we checked all the possible scenarios to confirm that nothing applies in my case :- 


Checked the user policy in central admin and there was nothing that was causing this issue





















Another possibility was to check if the farm admin account is operating as system account but that was also not the case.






Now another question came in my mind if this setting is not enabled then why does SharePoint showing system account at all. Strange but true. May be this setting is not at all applied on the farm account any by default it consider it as system account.



Then we checked the farm account is not set to the contributors ad account but it was correct and set to the farm admin account only





Then we checked if there is any problem with IIS pool Account and it was correctly set except that if was running as a specific user which is my farm admin account. Now I got the issue, this is the reason why all my users were being impersonated as system account. I changed it to Application user (pass-through authentication) and it solved the mystery. 






All my users are happy now as they can see their names as logged in user and and that makes me feel happy as well. It also solved lot of issues related to the authentication and access denied errors as and when user tries to perform any activity on which it doesn't has access by SharePoint.




Friday, January 3, 2014

How to programmatically update a content source in SharePoint 2010 enterprise / fast search

Following are the assembly references required to execute the code


using Microsoft.Office.Server.Search.Administration;
using Microsoft.SharePoint.Administration;
using Microsoft.SharePoint.BusinessData.Administration;
using Microsoft.SharePoint.BusinessData.Parser;
using Microsoft.SharePoint.BusinessData.SharedService;
using Microsoft.SharePoint.BusinessData.Infrastructure;
using Microsoft.BusinessData.Infrastructure;
using Microsoft.BusinessData.MetadataModel;
using Microsoft.Office.Server.Search;
using Microsoft.SharePoint.Search.Extended.Administration;
 
Here is the function that take two parameters as first is your central application url and other parameter to define if you want to configure fast search or enterprise search. You can use the code individually also in case you dont want to configure both.


public void UpdateContentSource(string WebAppUrl, bool IsFast)
        {
            try
            {

                string strContentSourceName = "<CustomContentSourceName>";
                string strLogSystemName = "<BDCLogSystemName>";
                //Content Source Update Started
                //execute this code if you are updaameting a fast search content source. else user for enterprise content source
                if (IsFast)
                {
                    foreach (SearchServiceApplication FASTServiceApp in SearchService.Service.SearchApplications)
                    {
                        SearchServiceApplicationType at = FASTServiceApp.SearchApplicationType;
                        if (FASTServiceApp.SearchApplicationType == SearchServiceApplicationType.ExtendedConnector)
                        {
                            Content FastContent = new Content(FASTServiceApp);
                            bool CheckExist = false;
                            ContentSourceCollection FastCSColl = FastContent.ContentSources;
                            foreach (ContentSource cs in FastCSColl)
                            {
                                if (cs.Name.Equals(strContentSourceName))
                                {
                                    CheckExist = true;
                                    Console.WriteLine(strContentSourceName + " FAST Search Content Source already exist");

                                }
                            }
                            BusinessDataContentSource CustomConSource = null;
                            if (CheckExist)
                            {
                                CustomConSource = (BusinessDataContentSource)FastCSColl[strContentSourceName];
                                if (CustomConSource.StartAddresses.Count > 0)
                                {
                                    CustomConSource.StartAddresses.Remove(BusinessDataContentSource.ConstructStartAddress("Default", new Guid("00000000-0000-0000-0000-000000000000"), strLogSystemName, strLogSystemName));
                                }
                                CustomConSource.Delete();
                                FastCSColl.Update();
                                Console.WriteLine(strContentSourceName + " FAST Search Content Source Deleted");
                            }

                            CustomConSource = (BusinessDataContentSource)FastCSColl.Create(typeof(BusinessDataContentSource), strContentSourceName);
                            CustomConSource.StartAddresses.Add(BusinessDataContentSource.ConstructStartAddress("Default", new Guid("00000000-0000-0000-0000-000000000000"), strLogSystemName, strLogSystemName));
                            CustomConSource.CrawlPriority = CrawlPriority.Normal;
                            FastCSColl.Update();
                            Console.WriteLine("External Source FAST Content Source Created");

                        }

                    }
                }
                else
                {
                    using (SPSite site = new SPSite(WebAppUrl))
                    {
                        foreach (SearchServiceApplication objServiceApp in SearchService.Service.SearchApplications)
                        {
                            if (objServiceApp.SearchApplicationType == SearchServiceApplicationType.Regular)
                            {
                                SearchServiceApplicationProxy proxy = (SearchServiceApplicationProxy)SearchServiceApplicationProxy.GetProxy(SPServiceContext.GetContext(site));
                                Guid appId = proxy.GetSearchServiceApplicationInfo().SearchServiceApplicationId;
                                SearchServiceApplication SearchApp = objServiceApp;         //SearchService.Service.SearchApplications.GetValue<SearchServiceApplication>(appId);
                                Content content = new Content(SearchApp);
                                ContentSourceCollection csColl = content.ContentSources;
                                bool CheckExist = false;
                                foreach (ContentSource cs in csColl)
                                {
                                    if (cs.Name.Equals(strContentSourceName))
                                    {
                                        CheckExist = true;
                                        Console.WriteLine(strContentSourceName + " is already exist");
                                    }
                                }
                                BusinessDataContentSource CustomConSource = null;
                                if (CheckExist)
                                {
                                    CustomConSource = (BusinessDataContentSource)csColl[strContentSourceName];
                                    if (CustomConSource.StartAddresses.Count > 0)
                                    {
                                        CustomConSource.StartAddresses.Remove(BusinessDataContentSource.ConstructStartAddress("Default", new Guid("00000000-0000-0000-0000-000000000000"), strLogSystemName, strLogSystemName));
                                    }
                                    CustomConSource.Delete();
                                    csColl.Update();
                                    Console.WriteLine(strContentSourceName + " Deleted");
                                }
                                CustomConSource = (BusinessDataContentSource)csColl.Create(typeof(BusinessDataContentSource), strContentSourceName);
                                CustomConSource.StartAddresses.Add(BusinessDataContentSource.ConstructStartAddress("Default", new Guid("00000000-0000-0000-0000-000000000000"), strLogSystemName, strLogSystemName));
                                CustomConSource.CrawlPriority = CrawlPriority.Normal;
                                csColl.Update();
                                Console.WriteLine("External Source Content Source Created");
                            }
                        }
                    }
                }

            }
            catch (Exception ex)
            {
                Console.WriteLine("Error:" + ex.Message);
            }
            Console.WriteLine("Content Source Update Ended");

        }