Skip to main content

Posts

Showing posts from March, 2012

Wildcard Module is not working for newly created page in Sitecore – 9

Wildcard Module allows us to work with Dynamic URL and Sitecore wildcard items.

Problem: In Sitecore instance, Wildcard module was working for a page when we initially configured for the first time. When we deleted that page and recreated that page again, wildcard module was not working. And it was not working for the newly created page in Sitecore. In Code-behind, it was not able to match the tokens in the particular URL.


Solution: In Sitecore \System\Modules\Wildcards\Routes\<BlogRoute>, we need to add items to create the rule for wildcard replacement. In that, we will be adding the pages to which wildcard to apply. When we add pages to Data Items, wildcard module will replace with tokens only to pages which match this Items Collection (GUIDs). So in order to use this wildcard route in other page or newly created page, we need to add the page explicitly in this data items as shown in below diagram. By doing this, Sitecore Wildcard module started to work for newly created page.


For…

How to use extension in the Sitecore Media Request URL – 8

Go to Web.config file and find a setting named “Media.RequestExtension” and remove the extension value.
<!--  MEDIA - REQUEST EXTENSION                The extension to use in media request URLs. If the value is not set, the Extension field of the individual media items will be used (ie. JPG, GIF, etc.)Default value: "ashx"-->      <settingname="Media.RequestExtension"value="ashx" />

Remove ashx from the value.       <settingname="Media.RequestExtension"value="" />

Sample: Before change      : /~/media/Images/logo.ashx After change         : /~/media/Images/logo.png (ashx also will work.)



How to allow dots(.) in Sitecore Item names – 7

Go to Web.config file and find a setting named “ItemNameValidation” and change the validation to allow dots.       <!--  ITEM NAME VALIDATION             Regular expression for validating item names   -->       <settingname="ItemNameValidation"value="^[\w\*\$][\w\s\-\$]*(\(\d{1,}\)){0,1}$" /> Modified Regular Expression.      <settingname="ItemNameValidation"value="^[\w\*\$][\w\.\s\-\$]*(\(\d{1,}\)){0,1}$" />


How to use SecurityDisabler and UserSwitcher in Sitecore v6.5 – 6

If current context user doesn’t have permission to access this item, Sitecore will return null or throw exception. 
Note: It is recommended to provide context user with appropriate rights than using SecurityDisabler or UserSwitcher.SecurityDisabler:  !SecurityDisabler will elevate the context user to have administrative privilegeand so context user will be able to do anythingon the system.new Sitecore.SecurityModel.SecurityDisabler();UserSwitcher:UserSwitcher allows a segment of code to run under a specific user instead of current context user. new Sitecore.Security.Accounts.UserSwitcher(Sitecore.Security.Accounts.User.FromName("username",false));Sample Code        ///<summary>/// Code snippets explaining SecurityDisabler and UserSwitcher///</summary>privatevoid SecuritySample()        {//Getting Master Database            Sitecore.Data.Database masterDB = Sitecore.Configuration.Factory.GetDatabase("master");//Getting a Sitecore Item            Sitecore.…

How to edit an Item in Code Behind (Sitecore v6.5) – 5

Sitecore will throw exception when editing an item if the item is not in editing mode. 
There are two ways where you can put an item in editing mode.1.Sitecore.Data.Items.ItemEditing2.Sitecore.Data.Items.EditContextScenarioSitecore.Data.Items.ItemEditingSitecore.Data.Items.EditContextTo begin editingItem.Editing.BeginEdit()Using(new Sitecore.Data.Items.EditContext(item))To Commit/End ChangesItem.Editing.EndEdit()If previous statement passes, automatically item changes will be committed.To Cancel EditItem.Editing.CancelEdit()If previous statement fails, automatically item changes will be rolled back.1.Sitecore.Data.Items.ItemEditingUnless and until, we call EndEdit() or CancelEdit(), Sitecore does not commit the changes.            //Getting Master Database            Sitecore.Data.Database masterDB = Sitecore.Configuration.Factory.GetDatabase("master");//Getting a Sitecore Item            Sitecore.Data.Items.Item home = masterDB.GetItem("/sitecore/content/Home");

How to access Sitecore Items in Code Behind (Sitecore v6.5) – 4

To get a Sitecore Content Item, use Sitecore.Data.Database.GetItem(Path)
­Sitecore Content Item Class: Sitecore.Data.Items.Item(Get Sitecore Item from “/sitecore/content/Home/myItem”)Sitecore.Data.Database master = Sitecore.Configuration.Factory.GetDatabase("master");Sitecore.Data.Items.Item myItem = master.GetItem("/sitecore/content/Home/myItem");If item does not exist or current context user doesn’t have permission to access this item, Sitecore will return null or throw exception. Case is Insensitive while using path to get the items.To get a Sitecore Template Item, use Sitecore.Data.Database.GetTemplate(ID)­Sitecore Template Item Class: Sitecore.Data.Items.TemplateItem(Get Template Item: Folder Template)Sitecore.Data.Items.TemplateItem item = master.GetTemplate(Sitecore.TemplateIDs.Folder);To get a Sitecore Media Item, use Sitecore.Data.Database.GetItem(Path)­Sitecore Media Item Class: Sitecore.Data.Items.MediaItem(Get Media Item from “/sitecore/content/Media Lib…

How to access Sitecore Content Database in Code Behind (Sitecore v6.5) - 3

Content Database:
Sitecore Content Editor primarily interact with Content database i.e. Master Database(by default).To get the content database, use the following property.Sitecore.Data.Database contentDB = Sitecore.Context.ContentDatabase; Note: Add Sitecore.Kernel.dll reference to project.

How to access Sitecore Database in Code Behind (Sitecore v6.5) - 2

There are three methods to work with Sitecore Database. To obtain it, you have to use Factory class Sitecore.Configuration.Factory. 
GetDatabase("Database Name"): Get Sitecore Database by NameSitecore.Data.Database database = Sitecore.Configuration.Factory.GetDatabase("DBName");You need to pass Database name as a parameter and it will return Sitecore Database Object.Note: “DBName” should match with ID of any /Configuration/Sitecore/Databases/Database and it is case sensitive.GetDatabaseNames(): Get all the Sitecore Database namesstring[] databases = Sitecore.Configuration.Factory.GetDatabaseNames();GetDatabaseNames method returns a string array with list of Database Names added in /Configuration/Sitecore/Databases/Database.GetDatabases(): Get all the Sitecore Databases Object in a ListList<Sitecore.Data.Database> databases = Sitecore.Configuration.Factory.GetDatabases();GetDatabases will return a list with all the Sitecore Database Objects configured in /Confi…

How to access Context Database in Sitecore v6.5 - 1

Sitecore has 3 databases: Core, Master and Web. Core has Sitecore Components; Master has all versioned files and unversioned content; Web has only latest (published) content.
Current Client Database When usingSitecore Client or any CMS client Core Database When usingPage Editor Master Database When browsing Published Site Web Database
Sitecore.Data.Database context = Sitecore.Context.Database;
Note: Add Sitecore.Kernel.dll reference to project.