Glass.Mapper.Sc Model Configurations(What/When/Why/How)

This blog is based on one of my recent experience where it was required to disable On Demand Loading of Model Configurations in an existing Sitecore 9 application using Glass.Mapper.Sc 5.

Majority of Model configurations in this application were done via Auto mapping and Attribute configurations.

I am sharing here learning I had and some of details regarding the Glass.Mapper.Sc configurations.

Setting Up the Context: Before mentioning the Steps I did for disabling On Demand loading – Let’s understand some details with respect to Model Configurations and their loading details.

What are the available Model Configurations

In Glass.Mapper.Sc – we have 3 ways to configure our mapping Model (Model Configurations)

  1. Automapping
  2. Attribute Configuration
  3. Fluent Configuration

What is On-Demand Loading :
Out of Box – Glassmapper supports On-Demand Loading – which means all the Model configurations will be loaded as and when Model call is made in the application.

Why would we need to disable On-Demand Loading.

  • to ensure all the Model configurations are loaded as part of application startup.
  • Would be handy for any Model Validation during application start up.
  • To avoid referred types being loaded incorrectly.

How to load Model Configurations explicitly:

  • via SitecoreAttributeConfigurationLoader : for Attribute Configurations defined in GlassMapperScCustom.cs
  • via SitecoreFluentConfigurationLoader : for Fluent Configurations defined in GlassMapperScCustom.cs

Steps performed:

  • explicitly set OnDemandMappingEnabled as “false” in App_Start\GlassMapperScCustom.cs
File : App_Start\GlassMapperScCustom.cs

  • Define Attribute Configuration Loader in App_Start\GlassMapperScCustom.cs

File : App_Start\GlassMapperScCustom.cs
  • Make sure all Models(Class/Interface) in the assembly has [SitecoreType] attribute defined.

  • This is required as we sometimes add field level attribute mapping and do not add SitecoreType attribute on Class/Interface.
Attribute Configuration Mapping.
  • In the application I was working had majority of configurations defined via auto-mapping (without any attribute configurations)- So next step was to go in each of such class/Interface and add attribute : [SitecoreType(AutoMap =true)] .

  • Field (which are auto-mapping enabled )- can be left as is.
Auto-Mapping Configuration.
  • Above 2 steps are requied as SitecoreAttributeConfigurationLoader looks for [SitecoreType] attribute while loading the Model configurations during application start up.

  • Without [SitecoreType] defined : class/interface is ignored, even if the properties have attributes defined.

  • The other option is to use Fluent Configurations for mapping Model as using Fluent Configuration ensures Configuration is loaded during application start up.
Fluent Configuration Mapping.

Happy Sitecoring!!


Install Sitecore 9 on Dev Box | A Step by Step Guide.

I know I am quite late. – “Better Late than Never” – This is what I said myself when I started exploring Sitecore 9 since last 1 week.
Had some glitches as well during my installation with initial version (Sitecore Experience Platform 9.0).

Many Thanks to below blogs/tutorials which helped me in my way, as and when I was stuck at various steps.


  • Windows 8.1/10.
  • .Net framewrok 4.6.2 or later.
  • SQL Server 2016  SP1
  • IIS 8.5 or 10
  • JRE(Java run time environment) is required for running SOLR.
  • Microsoft Powershell 5.1 +
  • Web Platform Installer 5.0
  • Web Administration Module with (IIS)- This should be installed by default with IIS 8.5 or 10.
  • Web deploy 3.6 for Hosting Servers. – via Web Platform Installer.
  • URL Rewrite 2+ . – Via Web Platform Installer.
  • Microsoft SQL Server Data – Tier Application Framework (17.1) – Via Web Platform Installer.
  • Microsoft SQL Server Transact-SQL ScriptDom Library- Via Web Platform Installer.

Let us follow below steps for installing Sitecore 9.0 in our local development Environment.

  1. Install SOLR 6.6.2 as Windows service. Earlier blog can be referred .
  2. Configure SSL for SOLR. Earlier blog can be referred .
  3. Setup an installation folder which will contain all required files which we will need to get sitecore 9 working with SIF(Sitecore Install Framework). In my case – I have created – D:\InstallSitecore9
  4. For SC 9.0 to be installed on local developer instance – We need On Prem XP0 instance packages. -> Sitecore 9.0.0 rev. 171002 (WDP XP0 packages).zip
    Get it from –
  5. Extract Sitecore 9.0.0 rev. 171002 (WDP XP0 packages).zip – which gives you 3 files.
    • Sitecore 9.0.0 rev. 171002 (OnPrem)_single.scwdp (.zip)
    • Sitecore 9.0.0 rev. 171002 (OnPrem)_xp0xconnect.scwdp (.zip)
    • XP0 Configuration files rev.171002 (.zip)
  6. Extract -XP0 Configuration files rev.171002 file – gives you below files.
    • sitecore-solr
    • sitecore-XP0
    • xconnect-createcert
    • xconnect-solr
    • xconnect-xp0
  7. Copy below files from the above extractions to the setup folder created in above step 3.
    • Sitecore 9.0.0 rev. 171002 (OnPrem)
    • Sitecore 9.0.0 rev. 171002 (OnPrem)
    • sitecore-solr.json
    • sitecore-XP0.json
    • xconnect-createcert.json
    • xconnect-solr.json
    • xconnect-xp0.json
  8. Grab the sitecore license file(license.xml) and place it in your setup folder as well.
  9. This is how the setup folder (D:\InstallSitecore9) should look like now-Blog4_Image1
  10. Setup SQL Server User – In past for all Sitecore installations I have been using sa user credential. In this step I will be setting up a standard user for all our Sitecore installations(having a ‘sysadmin’ role).
    • Open SSMS (SQL Server Management Studio) and connect to your local database.
    • Go to Security -> Login -> Add new Login
      • Your login name – I have given – “sclogin” for me.
      • Set your password.
      • Un-check Enforce Password policy.Blog4_Image3
      • From Server Roles – Give it a “sysadmin” server role and Click OkBlog4_Image4
    • Reconnect with newly created user – “sclogin” to verify if user is created successfully.
  11. Enable Contained Database Authentication- script is taken from Sitecore installation guide.
    • Launch MS SQL Server Management Studio and log in as an administrator
    • Run the following new query: – Can grab .sql file.
      sp_configure 'contained database authentication', 1;
  12. Now its SIF time  : “Sitecore Install Framework”
    • Open PS prompt as an administrator.
    • Register Sitecore repositories.
      Register-PSRepository -Name sitecoreRepo -SourceLocation
    • Install SIF Module
      Install-Module SitecoreInstallFramework
    • Install Sitecore Fundamentals Module.
      Install-Module SitecoreFundamentals
  13. At last – Now we are ready to run SC 9 installation script.
    • I have taken the script from SC9 installation guide and placed it in my setup folder – installsc9.ps1 . You can grab script I used from here: installsc9.ps1
    • Update all of the parameters accordingly in power shell script file- installsc9.ps1

      #define parameters
      $prefix = "learnsc9" ==> name for your sitecore instance
      $PSScriptRoot = "D:\InstallSitecore9" => setup folder which you have created in Step 3
      $XConnectCollectionService = "$prefix.xconnect"
      $sitecoreSiteName = "$"
      $SolrUrl = "https://localhost:8983/solr" => SOLR url - which I have setup in Step 1 and 2.
      $SolrRoot = "D:\SOLR\solr-6.6.2" => SOLR root folder which I have setup in Step 1.
      $SolrService = "solr662" => SOLR service name which I have setup in Step 1.
      $SqlServer = "LAPTOP-FT2VPMF2\SQLDEV" => Connection to my local database.
      $SqlAdminUser = "sclogin" => new login user which was created as part of Step 10
      $SqlAdminPassword="passwordforsclogin" => password which was setup as part of Step 10
    • Open Windows Power shell ISE as an administrator
      • Lets import both modules(SitecoreInstallFramework and SitecoreFundamentals) into our current session which we have installed in Step 12.Blog4_Image9
      • Browse for script file – installsc9.ps1  from the setup folder – D:\InstallSitecore9 (in my case)
      • Execute PS Script and Fingers Crossed.
      • Take a break – and you should be having your installation complete in next few minutes.Blog4_Image10
    • Verify SC 9 installation by opening up the instances.
    • Happy Me 🙂 – SC9 instance is up and running nowBlog4_Image11
    • Post Installation Steps. – Make sure the perform all the post installation steps mentioned in SC installation guide- Chapter 6.
      • Rebuild the Search Indexes
        • From Sitecore Launchpad, click Control Panel =>Indexing section => click Indexing manager.
        • Indexing Manager dialog box => click Select all => click RebuildBlog4_Image12
      • Build the Link Databases
        • Sitecore Launchpad=> Control Panel => Database section => click Rebuild Link Databases.
        • Select the Master and Core databases and then click Rebuild.Blog4_Image13
      • Add a Recognized User to the xDB Shard Databases
        • Query can be grabbed from SC installation guide
        • We need to update DatabasePrefix as per our installation.
        • I have updated script it as per the current instance we have installed.:SETVAR DatabasePrefix learnsc9
        • Execute the Query in SSMS.Blog4_Image14
      • Deploy Marketing Definitions
        • Sitecore Launchpad => Control Panel => Analytics => click Deploy Marketing Definitions.
        • select all the definitions and taxonomies and click Deploy.Blog4_Image15
  14. Wow !!!- We have successfully installed – up and running SC 9.0 instance in local developer box.

Happy Sitecoring !!

Secure SOLR Service for Sitecore 9 | Configure SSL for SOLR.

This blog is my experience of taking me one step closer to Sitecore 9 installation.  Its an extension of my previous post of setting up SOLR as Windows Service . After setting up SOLR as windows service I verified SOLR admin page with URL -http://localhost:8983/solr/

Purpose of this blog is to make it https => an extra s , that’s it!!! 🙂

In SC 9 SOLR by default needs to be setup in secure way. As this is for my local dev box I am going ahead with self signed certificates. Credit to Kam for providing us with a handy Power shell Script for generating self signed certificate and installing it .

Follow the below Steps for securing your SOLR Service in your local dev box.

  1. Go to Kams webiste – and get the original PS script.(solrssl.ps1) . Many Thanks to Kam Figy for it.
  2. Script makes use of Java keytool which is a certificate manager.
  3. Figure out your  keyttol.exe path from java directory in your PC. I have mine at  C:\Program Files\Java\jre1.8.0_181\bin\keytool.exe Blog3_Image1
  4. Open the script(solrssl.ps1) in an editor – and go to Line # 37
    $keytool = (Get-Command 'keytool.exe').Source
  5. Update Line #37 as below depending on your keytool.exe path figured out in previous step
    $keytool = (Get-Command 'C:\Program Files\Java\jre1.8.0_181\bin\keytool.exe').Source
  6. Check for updated PS File : solrssl.ps1
  7. Open Power shell as administrator and navigate to folder where you have kept PS file – solrssl.ps1 (from previous step)Blog3_Image2
  8. Pass in location for the keystore file.
    .\solrssl.ps1 -KeystoreFile D:\SOLR\solr-6.6.2\server\etc\solr-ssl.keystore.jks
  9. Execute PS and your keys are generated.Blog3_Image3
  10. In case of Error- ” “File [.ps1] cannot be loaded because the execution of scripts is disabled on this system.”  – Execute below line on Power shell window and re-run Step 8
    Set-ExecutionPolicy -Scope CurrentUser Unrestricted
  11. Verify if keystore files are created in location which we provided . In my case – i checked at path – D:\SOLR\solr-6.6.2\server\etcBlog3_Image4
  12. Based on Next Steps from PS output of Step 9 – Open your file which should be inside bin folder of your SOLR installation folder. In my case its in – D:\SOLR\solr-6.6.2\bin\
  13. Search for below 4 lines in file , un-comment all 4 lines and save the changes.
    set SOLR_SSL_KEY_STORE=etc/solr-ssl.keystore.jks
    set SOLR_SSL_TRUST_STORE=etc/solr-ssl.keystore.jks
  14. Restart your SOLR Service from Service Manager.
  15. Check SOLR admin page – http URL- http://localhost:8983/solr/   – Yes this Page should not work now.
  16. Add an extra “s” – and open it securely – https://localhost:8983/solr/Blog3_Image7

With this I am done securing my SOLR Url and excited – as now I am ready to install Sitecore 9.

Happy Sitecoring !!