Saturday, February 16, 2019

Issue with Exm contacts Sitecore 9

Encountered below error in Exm in sitecore 9.




Below is the error in the log file.

ERROR [Sitecore Services]: HTTP GET
URL http://[hostName]/sitecore/api/ssc/ListManagement/ContactList?pageSize=20&pageIndex=0&payLoad=full&language=en&rootId=&filter=getSegmentedLists&searchExpression=&sc_lang=en

Exception System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.IndexOutOfRangeException: Index was outside the bounds of the array.
   at Lucene.Net.Util.BitVector.Get(Int32 bit)

Resolution: The above issue got resolved after completing rebuilding the search indexes & "sitecore_list_index".


Tuesday, February 5, 2019

Sitecore Multi-Site best Practices

    
1. Create role for each site (SiteA, SiteB) which will have same access rights as Sitecore admin Role however each role will have access to its own site node and associated nodes (such as template, layout, renderings, Media library).

2. Create content Author Role for each site which will have access to respective site node and media library only (restrict access to other nodes).

3. If there are any shared contents which both sites need access to in the future, should be kept outside home node and respective roles should have access to it.

4. Separate site configuration items and global configuration items

5. Organize template, media library, layouts and renderings in site specific folder.

6. SiteResolving should be set true for internal links to consider different domains. Refer the link for more info https://briancaos.wordpress.com/2012/03/28/sitecore-links-in-multisite-solutions-siteresolving/

7. Need to use patch to add site configuration and need to follow the naming conventions for config file if both the sites are sharing the same website folder.


Sitecore Commerce update2 installation in few steps


First step is to install Sitecore 9 update2, to install Sitecore 9 please follow below steps
     1. Set up Solr 6.6.2, follow this blog post in Setting up Solr Make sure your solr is up & running.
     2. To install sitecore 9 follow this link sitecore-9-0-2-installation
     3. Download installation scripts from this link sitecore 9 installation.

For Sitecore commerce installation make sure sitecore 9 update2 instance and Solr is up and running.
Please follow steps for Sitecore commerce 9 update 2.

Download required prerequisites

1. Download and Install .NET Core 2.0
2. Download and Install .NET Core Windows Server Hosting 2.0.0
3. Download Sitecore Powershell Extensions 4.7.2 from Sitecore Marketplace
4. Copy downloaded file into folder "C:\deploy\assets", Please see the below screen shot for the same
   



Deploy folder with necessary assets already downloaded for you guys, Please click here to download installation files

Commerce 9 update2 installation issues & resolutions

Issue3: One or more exceptions occurred while processing the subscribers to the 'item:saved' event.
Resolution : 
Make sure the xConnect site works with SSL(https).
If xConnect site does not work, alternative solution to would be to comment out the item:saved event.

Go to the web site path “\App_Config\Sitecore\ExperienceAnalytics\Sitecore.ExperienceAnalytics.Client.config” comment out

<event name="item:saved">


Issue4: Ensure/Sync default content paths for: AdventureWorksAuthoring
Ensure/Sync default content paths for environment AdventureWorksAuthoring failed, please check Engine service logs for more info.


Resolution :
Previous steps took long time to execute and operation might have timed out. To solve this issue increase the timeout setting value in "SitecoreUtilityTasks.psm1" file for all the operations located under "C:\deploy\SIF.Sitecore.Commerce.1.2.14\Modules\SitecoreUtilityTasks"  and
Change the connection string in identity server appsetting file to
"ConnectionString":"DataSource=LIN34003551;userid=sa;password=Param@123;Database=storefront_Core",

Re-run the installation from where it has stopped.

References
https://buoctrenmay.com/2018/03/09/step-by-step-guide-for-sitecore-commerce-9-installation-on-your-machine/

Tuesday, October 9, 2018

Sitecore Certification Ques Part2


 What happens if a role denies an access right and another one allows it?
It is denied

 Placeholder override
This means creating a different configuration for the same placeholder for different parts of the site. In this case, the Home page should be treated differently to the rest of the site and not allow adding or removing components from the main placeholder.

 Using Edit Frames to Edit Complex Fields in the Experience Editor
On that edit frame, you will add a Field Editor button that will allow authors to modify the Related item field directly from the Experience Editor.
Go Core database and locate the item: /sitecore/content/Applications/WebEdit/Edit Frame Buttons
Create an item based on the Edit Frame Button Folder template and call it Related Events.
Under the Related Events folder, create another item based on the Field Editor Button template called Edit Related Events.

 Describe some xWeb Content Management System features that separate Sitecore from other systems.
    Analytics, Insights, Decisions, and Automation


What field type would you use to store formatted HTML?
     Rich Text field

What happens if you use the same field name in a template that is already used in a parent template?
      You will get two fields with the same name, which leads to confusion both to users and developers, It should be avoided.


What would you use the Field source for in the following field types: Image, Rich Text Field, Droplink?
Image: Set the folder in the Media Library it will open when selecting an image for the field.
Rich Text: Configuration of the toolbar and functionality of the Rich Text Editor.
Droplink: Set the items to be displayed as options.


What happens if you don't set any insert options?
     Only admins and privileged users will be able to create content (using the Insert from template option).

 Where should you set insert options as a best practice?
    In the Standard Values, so they are applied as a default to newly created items.

 If you set up some publishing restrictions, will Sitecore automatically publish that content at that exact time?
      No. The publishing restrictions only dictates when an item or its versions are publishable or not.

Why would you need to use the data source in a component?
      The data source allows you to build more flexible and re- usable components because the data source is determined by users and not hardcoded by developers.

 Can you use placeholders inside of placeholders?
      Not directly. However, you can have components inside a placeholder that in turn define other placeholders. This is referred to as nested placeholders.

 Why is it a good idea to avoid using Rich Text fields as much as possible?
    One of the benefits of using Sitecore is the separation of content and presentation. The Rich text field is the only exception to this, as it stores HTML content directly. If abused and not configured properly, it may give users the ability to break the design of the site.

What do you need to do to allow users to add and remove components from a placeholder using the Experience Editor?
               Create a Placeholder Settings item for that placeholder.

 Which fields are editable inline using the Experience Editor?
     Text fields (Single-Line, Multi-Line, Rich Text),
      Date/DateTime, Image, General Link.

 Give an example of when you would use the DisableWebEdit parameter when rendering a field.
    Rendering a field inside the <title> tag in the <head> of the HTML


What is the main purpose of a Web Content Management System?
Offers a content storage system
Provides log in functionality to a website
ü  Allows non-technical users to administer the content of a website
Speeds up the performance of a web server

Why does Sitecore have both a Master and Web database?
To be able to have multiple servers delivering your live site content
To make version upgrades much easier
ü  To allow editing content in a sandbox without affecting the content on the live site
To separate your own configuration from the standard one that comes with Sitecore

 Which of the following best describes the purpose of the Field Source in Sitecore?
The Field Source defines how fields appear in the UI
The Field Source is only used to restrict a user's access to folders and files
A Field Source maps a field to the underlying class representation in the API
ü  The Field Source allows the configuration of extra properties in a template's field definition

 How can you populate the property of a ViewModel and still support inline editing in the Experience Editor?
By using the appropriate field class as the type of the property
ü  @ By using the Render() method in the FieldRenderer class
By using an object from the FieldsCollection
By wrapping the entire markup in a Sitecore Edit Frame

 When you use the field helper, what do you do when you want to ensure that a field cannot be editable inline?
Choose a non-editable equivalent field type
ü  Use the DisableWebEdit option
Set the Editable parameter to False
Mark the field as non-editable in the field definition item

 What is the advantage of using components?
It allows content to be editable inline through the Experience Editor
You can include content from Sitecore
ü  Your presentation artifacts are more reusable
You can have different output depending on the device requesting the page

How can you define renderings as compatible?
Ensuring they have the same name prefix
Adding an attribute in their implementation file
@ Having them in the same Allowed Controls field of the placeholder
ü  Modifying a field in their component definition item

Where does Sitecore store the Rendering Parameters?
Only fields that support edit frames
Fields that contain simple values: single-line text, checkbox or integer.
ü  Any Sitecore field
Fields that have been registered with the component

 In a view, what do you need to do so the Field() extension method retrieves the content from the datasource?
You have to use the FieldRenderer as the Field method can't do that.
Pass a second parameter :Field("fieldname",Model.Rendering)
Pass an anonymous object with the item reference: Field("fieldname", new
(Item-Datasource)
ü  Nothing, that is its default behavior

 How can you retrieve the Datasource in a view rendering with the default model?
Model. Rendering. Item
ü  @ Model. Item
Model. Datasource
Model. RenderingContext. Item

How can you get Sitecore to produce translated URLs?
By using the languageLocation attribute of the LinkManager
By configuring the EncodeNameReplacements
By using the GetFriendlyUrl method
ü  By setting the LinkManager to use the item's DisplayName

When you patch in changes to the Sitecore.config file through Include Files, in which order are your changes applied?
Using the Priority attribute when you create the change
In App Config, create «ordep entries in the patchOrder.config file
According to the updated date timestamp of the Include File.
ü  @Alphabetically according to the name of the file and subfolder

What is the raw value of a field?
The value the user typed in the Content Editor
The binary representation of the contents of the field
ü  The value of the field as stored in the database
The value returned by the FieldRenderer

 What is the advantage of setting StorageType-Yes in an index field?
The tokenization process will be more efficient
ü  There is no need to access Sitecore database to query its value
Update index operations will be faster
The index will take less space



Sitecore® 9.0 Certified Platform Associate Developer

Today I cleared Sitecore® 9.0 Certified Platform Associate  Developer exam.

Here are the few references which helped me in preparing for exam :

Reference Materials/Sites:  30 -40% of questions were from below two reference sites & 15% questions from Sitecore essentials e-learning modules.



3 to 4 Question on Edit Frames

1 question on dynamic placeholder

1 must question on Docs & Support
some on sitecore Rocks such as creating anti package & short cuts

one question on scalling

2 to 3 questions on inheritance

2 questions on item buckets

questions on field types



Wednesday, June 27, 2018

Tuning web page performance


1.    Why parallel api call?

If the page needs to make multiple web requests (multiple api calls), we might end up in page performance issue (page load time might be higher) if the one of the api is taking longer time and blocking the other of the api calls.

I had also encountered page load time issue in one of my project. Page was consuming 12 different api, 4 api calls were taking longer time (more than a minute) and blocking the execution of the other of the api calls.

To overcome the above issue, I have made use of async and await keywords of C# and Parallel.ForEach method where there were multiple api calls inside for each.

2. Overview of the parallel implementation  


In an async method, tasks are started when they’re created. The await operator is applied to the task at the point in the method where processing can’t continue until the task finishes.

 var result = await WebRequest(url); 

In the above example task is waited as soon as it is created, however you can separate creating the task from awaiting the task if your program has some other task to accomplish in between that doesn’t depend on the completion of the task.

// The following line creates and starts the task.
var task1 = WebRequest(url); 


// While the task is running, you can do other work that doesn't depend 
// on the results of the task1.


// the application of await suspends the rest of this method until the task is complete.
var result = await task1;

1.     Sample example of parallel api call.


Below program starts three asynchronous web api calls and then awaits them in the order in which they’re called. Below web request don’t always finish in the order in which they’re created and awaited. They start to run when they’re created, and one or more of the tasks might finish before the method reaches the await expressions.
        private async Task<int> GetTotalContentLenght()
        {
          HttpClient webClient = new HttpClient();
            Task<int> webRequest1 = GetContentLength("http://msdn.microsoft.com", webClient);
            Task<int> webRequest2 = GetContentLength("Url", webClient);
            Task<int> webRequest3 = GetContentLength("Url", webClient);
            int length1 = await webRequest1;
            int length2 = await webRequest2;
            int length3 = await webRequest3;
            int totalLength = length1 + length2 + length3;
            return totalLength;
        }

        async Task<int> GetContentLength(string url, HttpClient client)
        {
          var byteArray = await client.GetByteArrayAsync(url);          
            return byteArray.Length;
        }

2.     Paralle.ForEach

   List<string> urls = new List<string> {  "URL 1",   "URL2",   "URL 3",   "URL 4",    "URL 5" };
Parallel.ForEach(urls, async m =>
   {    
byte[] urlContents = GetURLContentsAsync(url);  //web api call
int total+= await urlContents.Length;                         
});

3.    References

1.     https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/async/how-to-make-multiple-web-requests-in-parallel-by-using-async-and-await

Redis Cache


1.    What is Redis Cache?

Caching is a state management strategy that can be used to improve the performance of your applications as it helps you to reduce the consumption of resources in your system.

Redis Cache is an open source (BSD licensed), high-speed, NoSQL database. It's fast, and it runs entirely in the memory with negligible performance overhead when reading and writing data. It should be noted that Redis is free for both commercial and non-commercial use under the BSD license.

2. Install and proceed with Redis Cache implementation


Once the Redis database setup is done, we need Redis client to store and retrieve the data to and from the Redis cache.

Step 1>

1.     Install StackExchange.Redis package from nugget package.


Once the StackExchange.Redis installation is done. Please follow the below steps to store and retrieve data to and from the Redis cache.

Step2 >

2.     Open connection to Redis Cache


  Var RedisConnectionString=connection string
 if(RedisConnection.IsConnected)
   {
      Var ServerCache = RedisConnection.GetServer(RedisConnectionString);
      Var DBCache = RedisConnection.GetDatabase();
            HttpContext.Current.Application["RedisDB"] = DBCache;
    }

Step3 >

3.     Set the data in the Redis

Var _database= System.Web.HttpContext.Current.Application["RedisDB "];
   if(_database != null && _database.IsConnected(key))
      {
        ISerializer _serializer = new JsonSerializer();
        _database.StringSet(key, _serializer.Serialize(value), RedisExpireIn);

       }



Step4 >

4.     Get the data from Redis Cache

Var _database= System.Web.HttpContext.Current.Application["RedisDB "];
ISerializer _serializer = new JsonSerializer();
                if (_database != null && _database.IsConnected(key))
                {
                    _serializer.Deserialize<T>(_database.StringGet(key));
                }
               
       

5.     Delete key from Redis Cache


if (_database != null && _database.IsConnected(key))
                {
                   _database.KeyDelete(key);
                }

6.     Extending the Cache key Expiry


Var _database= System.Web.HttpContext.Current.Application["RedisDB "];
_database.KeyExpire(key, RedisExpireIn);

3. Reference