Skip to main content

Posts

Automatically create new version for Lock & Edit without workflow

Sitecore will create a new version on Lock and Edit if the item is tied to a workflow. For our case, version has to be created even without using workflow.
As mentioned by Dylan here, we can override the default behavior of Sitecore. Here we overridden the “Checkout” command which is executed on Lock & Edit.
Added a setting called EnableAddVersionWithoutWorkflow as a flag to enable this feature. If it is true, it will add a version and lock the new version for the user.
Note: By default, only a non-admin user will see the lock and edit button for an item. 
if (!item.Locking.IsLocked())             { Log.Audit(this, "Start editing: {0}", newstring[]                 { AuditFormatter.FormatItem(item)                 }); if (Context.User.IsAdministrator)                 {                     item.Locking.Lock();                 } elseif (bool.Parse(Settings.GetSetting("EnableAddVersionWithoutWorkflow", "false")))                 { Error.AssertObject(item, "item&q…
Recent posts

Access denied when attaching new media item.

When a Sitecore non-admin user tries to attach a media item, access denied error appears. 
This is due to incorrect Security settings in Sitecore. 
My Sitecore Version:  8.1 (rev. 160519)

Solution by Kasaku

3272 11:36:34 ERROR Application error.
Exception: System.Web.HttpUnhandledException
Message: Exception of type 'System.Web.HttpUnhandledException' was thrown.
Source: System.Web
   at System.Web.UI.Page.HandleError(Exception e)
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
   at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
   at System.Web.UI.Page.ProcessRequest()
   at System.Web.UI.Page.ProcessRequest(HttpContext context)
   at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

Nested Exceptio…

Sitecore – Contextual shortcut menu

This is a simple idea to bring few chunk items into the contextual menu. It has Layout Details, Publish Item, Preview, Experience Editor, Display name.

You can download the package here.

Redirect restricted media items with ReturnURL

Sitecore can redirect the user to login page if the requested item is restricted for anonymous users. This can be done in the Site configuration. 

requireLogin="true"
loginPage="/redirectpage"

There are two differences in this redirection. For Sitecore item, it will be redirected with returnURL querystring with source url. For Media item, querystring is not added. 

In one of the project, we had to handle the redirection based on the source url for the Sitecore Media items. To achieve this, MediaRequestHandler can be modified and it will return a query parameter with source URL. Please make sure to update the <handler> with the new class and assembly name. 

        /// <summary>
        /// Performs the actual request processing.
        /// </summary>
        /// <param name="context">
        /// The context.
        /// </param>
        /// <returns>
        /// The do process request.
        /// </returns>
        protected…

Sitecore generate dynamic URL

When we migrate a site from legacy platform to Sitecore, there may be cases where Sitecore Rich Text Editor will have links. These html content with links will have relative URL and it may break if we move the page to different folder in Sitecore. 

Sample HTML Content:
<p>Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five <a title="centuries" href="/about-us/centuries">centuries</a>, but also the leap into electronic typesetting, remaining essentially unchanged.</p>

In order to set the links with Dynamic URL, we need to read the HTML content (via HtmlaAgilityPack), find the links, generate the dynamic URL and save it. 

To generate the Dynamic URL, we can use the below method. 

For Sitecore Item:
LinkUrlOptions options = new LinkUrlOptions();
var dynamicUrl = LinkManager.GetDynamicUrl(item, options…

Get fallback language in code

With the latest Sitecore version, Language Fallback is a key feature for multilingual website. 

Sitecore does the job to get the fallback version and languages for us. 

If you want to get the Fallback Language object, one of the way is below.


            var fallbackLanguage = Sitecore.Data.Managers.LanguageFallbackManager.GetFallbackLanguage(Sitecore.Context.Language, Sitecore.Context.Database);

Sitecore MVC – Custom Vary by cache options

Sitecore, by default, provides varies options like Vary by Data, Vary by Query String to enable HTML cache. Sometimes none of these options (based on component built type) help the component to get cached by Sitecore cache.
This module helps in adding options to cache based on URL and Rendering Unique ID.
After installation, you will see two options in caching section of rendering definition. -Vary by URL Cache key varies by HttpContext AbsolutePath Can be combined with other options like query string (existing) -Vary by Unique ID Uses rendering unique ID
Also, page presentation component properties will have the same option and there will be an additional option to disable the rendering definition cache settings – Cancel Cache Settings. (ref link)
Now you enable cache based on incoming URL and rendering Unique ID. Also disable the rendering cache setting in Page presentation component properties.