24 May 2015

LockObtainFailedException and SwitchOnRebuildLuceneIndex in Sitecore 7

"LockObtainFailedException" is a common error in Sitecore 7. For most of the cases, it will occur when you try to access the index file while the index is still building. The error will looks like something like below,


In Sitecore 7, it introduces the "SwitchOnRebuildLuceneIndex". (Sitecore.ContentSearch.LuceneProvider.SwitchOnRebuildLuceneIndex) It will create a "xxx_sec" .e.g "sitecore_index_web_sec)" index folder and build a new set of indexes for Sitecore to switch on when rebuilding index is happening.



I recommend Sitecore set this as default provider.

22 May 2015

Stop Words with Custom Search Analyzer in Sitecore 7

As we know, at least in Lucene.NET 3.x.x version, the "stop words" are hand coded in this class "Lucene.Net.Analysis.StopAnalyzer". It does making the customizing the stop words a bit of tricky, especially for specific index since for the most of cases, you only need to customize one of the custom index to suit clients need. Here is a way how we can achieve that.

By default, Sitecore use "Lucene.Net.Analysis.Standard.StandardAnalyzer" and you can find it in wbe.config.(/configuration/sitecore/search/analyzer)


We create a new custom Analyzer inherit from "standardAnalyzer" and override the constructor. Here is the place I assign my own custom stop words to "STOP_WORDS_SET"
public class CustomAnalyzer : Lucene.Net.Analysis.Standard.StandardAnalyzer
{
        private static ISet STOP_WORDS_SET = GetStopWords();//{{"by","by"}}; <-- Makes "by" a 
       
        public CustomAnalyzer()
            : base(Lucene.Net.Util.Version.LUCENE_30, STOP_WORDS_SET)
        {      
        }

        private static ISet GetStopWords()
        {
            string[] strArray = GetWords();
            CharArraySet set = new CharArraySet(strArray.Length, false);
            set.AddAll((IEnumerable)strArray);
            return (ISet)CharArraySet.UnmodifiableSet(set);
        }
}

After, under "/configuration/sitecore/search/analyzer" in web.config, we wire the custom analyzer as below,

      
        Lucene_30
      

Don't forget to register it from you custom index file





Done!!!

14 May 2015

Access to the registry key 'Global' is denied in Sitecore

My ECM would not send any email. By looking into the logs, I can see there is some issue when initializing the CPUAvgPerformance as below.

ManagedPoolThread #16 18:39:46 ERROR EmailCampaign: Error on Initializating CPUAvgPerformance with exception: System.UnauthorizedAccessException: Access to the registry key 'Global' is denied.
   at Microsoft.Win32.RegistryKey.Win32Error(Int32 errorCode, String str)
   at Microsoft.Win32.RegistryKey.InternalGetValue(String name, Object defaultValue, Boolean doNotExpand, Boolean checkSecurity)
   at Microsoft.Win32.RegistryKey.GetValue(String name)
   at System.Diagnostics.PerformanceMonitor.GetData(String item)
   at System.Diagnostics.PerformanceCounterLib.GetPerformanceData(String item)
   at System.Diagnostics.PerformanceCounterLib.get_CategoryTable()
   at System.Diagnostics.PerformanceCounterLib.CounterExists(String category, String counter, Boolean& categoryExists)
   at System.Diagnostics.PerformanceCounterLib.CounterExists(String machine, String category, String counter)
   at System.Diagnostics.PerformanceCounter.InitializeImpl()
   at System.Diagnostics.PerformanceCounter..ctor(String categoryName, String counterName, String instanceName, Boolean readOnly)
   at System.Diagnostics.PerformanceCounter..ctor(String categoryName, String counterName, String instanceName)
   at Sitecore.Modules.EmailCampaign.Core.Dispatch.CpuAvgPerformance..ctor()
   at Sitecore.Modules.EmailCampaign.Core.Dispatch.TimeSummary..ctor()


How to fix it?


  1. Go to "Computer Management - System Tools - Local Users and Groups - Groups - Performance log Users" and add the "User" running your AppPool into this group


  2. If you are using "ApplicationPoolidentity" running your AppPool. use "IIS AppPool\AppPoolName"

Note: After that, you need to "Restart the IIS" or "Stop/Start" AppPool. Recycle AppPool will not help.

Helps?


08 May 2015

Hidden Items - Missing layout System and templates in Sitecore Content Editor

You wake up in the morning and login Sitecore content editor as Sitecore Administrator. WOW, where is my "layout", "templates" and "system" node?




It turns out easy to fix unless you did something really wrong with security last night. 
Go to "View" and check "Hidden Items"




It works and that is half a hour debugging time I never get back



06 May 2015

Set up validation rules to prevent user from saving in Page Editor Mode using Sitecore

I recently encountered a scenario that in page editor mode, the client want to prevent content user from saving when the validation rules breaks which is not a default behavior. Here is how we can easily achieve it in sitecore.

Only CriticalError and FatalError will give your the pop up to tell you something is not right in page editor mode. The difference is FatalError will prevent you from saving and CriticalError will not but only with pop up warning message.





It is very easy to set up!


04 May 2015

Limit editing HTML source for rich text editor field in Sitecore

I recently get a requirement about limiting the way of editing ram html in Rich Tex Editor. After a few digging around the Sitecore, here is how I figured.


There are two places in Rich Text editor you can change the html markup in Content Editor.

1st place

2nd place


For 1st place, goes to Core database "/sitecore/system/Field types/Simple Types/Rich Text" and in "Security Editor" to deny "read" for both items as highlighted for the "Sitecore Roles" you prefer.





For 2nd place, it is a bit of tricky. We first need to find out what is our default profile is by going to web.config.

<setting name="HtmlEditor.DefaultProfile" value="/sitecore/system/Settings/Html Editor Profiles/Rich Text Default" />

After that, we located this profile in "Core" database and locate 
"/sitecore/system/Settings/Html Editor Profiles/Rich Text Default/Buttons/HTML View"


So we need to do the same by deny "read" from "Security editor" for certain roles as well.


Done!

WFFM Web form for marketer fail to submit in Sitecore

I have setup a standard form using WFFM in Sitecore 8.2. It always fail when submit. Error as below, Error: Exception: System.Data.DataE...