1

My Site configuration looks like this:

<site name="sitename" patch:after="site[@name='web_module'] targetHostName="HostName" 
              database="web" 
              virtualFolder="/" 
              physicalFolder="/" 
              rootPath="RootPath" 
              startItem="/Home" 
              dictionaryPath="DictionaryPath" 
              dictionaryAutoCreate="false" 
              placeholderSettingsRoot="PlaceholderSettingsRootPath"
              domain="extranet" 
              allowDebug="true" 
              cacheHtml="true" 
              htmlCacheSize="50MB" 
              registryCacheSize="0" 
              viewStateCacheSize="0" 
              xslCacheSize="25MB" 
              filteredItemsCacheSize="10MB" 
              enablePreview="true" 
              enableWebEdit="true" 
              enableDebugger="true" 
              disableClientData="false" 
              cacheRenderingParameters="true" 
              renderingParametersCacheSize="10MB" 
              formsRoot="formsRootGUID"
              loginPage="/login"
              enableItemLanguageFallback="true" />

However if I use the Sitecore.Context.Database to get the context to get items, it returns master instead of web in sc_mode=normal.

Sitecore.Data.Database context = Sitecore.Context.Database;

Why is it so and what could possibly go wrong?

Thanks!

5
  • And where do you use this code? Is it a controller? Some background code? Have you tried with ?sc_mode=normal parameter?
    – Marek Musielak
    Commented Feb 7, 2018 at 6:56
  • this is being used in a private method called from the controller. Yup, for SC_mode=normal it returns Master instead of Web Commented Feb 7, 2018 at 7:13
  • 1
    And what returns Sitecore.Context.Site.Name and Sitecore.Context.Site.Properties["database"]?
    – Marek Musielak
    Commented Feb 7, 2018 at 7:53
  • 1
    Is the above config from /sitecore/admin/showconfig.aspx? Else check using that and make sure you do not have the LIveMode.config enabled.
    – jammykam
    Commented Feb 7, 2018 at 14:43
  • Thanks @jammykam. No, this was not from showconfig.aspx and after seeing your comment, I went to showconfig.aspx and the database was master there.After digging in further, I figured out the database was patched to master in a different config devsettings Commented Feb 9, 2018 at 6:53

2 Answers 2

3

It is not uncommon for developers or certain servers to be configured to run in "Live Mode", by patching the database attribute to master. By using this setting it allows you to view the site without needing to publish or put items through any workflows.

If the database attribute has been patched then Sitecore.Context.Database will return that value, i.e. master, even in normal mode.

In a default instance of Sitecore, a sample config patch file named LiveMode.config.example is provided for the website site, for example:

<sites>
  <site name="website">
    <patch:attribute name="database">master</patch:attribute>
    <patch:attribute name="filterItems">true</patch:attribute>
    <patch:attribute name="enableWorkflow">true</patch:attribute>
  </site>
</sites>

You should verify your site configuration by browsing to /sitecore/admin/showconfig.aspx which will show the final configuration after all the config patches have been processed and applied.

If the setting is different then it must have been patched by another config file. Often the config will show an extra attribute such as patch:source="LiveMode.config" which will tell you where it was patched from otherwise search the contents of the files in the Include folder.

3

It means that you're not in the scope of the site you added in your question or you're inside a DatabaseSwitcher context.

Looking at the config (especially empty virtual and physical folder), I'm guessing that your site may be added after another site which accepts same urls.

Check Sitecore.Context.Site.Name and Sitecore.Context.Site.Properties["database"] to see which site context is used in your method.

1
  • Thanks! After seeing @jammykam's comment, I went to showconfig.aspx and the database was master there.After digging in further, I figured out the database was patched to master in a different config - devsettings Commented Feb 9, 2018 at 6:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.