Pages

22 July, 2012

Sitecore: Disable Sitecore cache and browser cache while developing to save time


It is always to have cache in any web application. But while in development stage, it is better to disable Sitecore cache and also browser cache to avoid wasting time in recycling application pool or clearing cache from cache admin. To disable it,

      <!--  CACHING ENABLED
            Determines if caching should be enabled at all
            Specify 'true' to enable caching and 'false' to disable all caching
      -->
      <setting name="Caching.Enabled" value="true" />
      <!--  DISABLE BROWSER CACHING
            If true, all pages will have:
              Cache-Control: no-cache, no-store
              Pragma: no-cache
            in the http header
      -->
      <setting name="DisableBrowserCaching" value="true" />

Both the setting should be true; former to avoid Sitecore cache and latter to BrowserCache.

Avoid locking of items by a user in Sitecore


In Sitecore, many users will work parallelly and locking of item will not allow another user to work on the same item. To avoid locking and loss of changes, we have settings in the web.config.

      <!--  AUTOMATIC LOCK ON SAVE
            If true, the a lock is automatically taken on an item
            when a user saves the item.
      -->
      <setting name="AutomaticLockOnSave" value="false" />
      <!--  AUTOMATIC UNLOCK ON SAVED
            If true, the a saved item is automatically unlocked after
            saving.
      -->
      <setting name="AutomaticUnlockOnSaved" value="false" />

Both the setting should be true; former to avoid data loss and latter to avoid locking of items.

Access issue with language security settings

Sometimes we used to get errors like “The Security settings for the current language prevent you from seeing this item.”









This is due to that Language Item under system is not having read and write access (atleast read). Please give Language Read and Write access and you will be allowed to edit whichever items you have access.


Problem with downloading Media files from Sitecore if Windows Authentication enabled

UAT environment used to be locked with Windows/Basic Authentication. There is an issue with Sitecore media items (mainly XSLT) when site is locked with Windows Authentication. 401 unauthorized issue. We need to give anonymous access only to media items like XSLT. Thanks to Ankit Agarwal who gave the solution.

In applicationHost.config, add these lines,
<location path="<Sitecore>/~/media">
        <system.webServer>
            <security>
                <authentication>
                    <anonymousAuthentication enabled="true" />
                    <basicAuthentication enabled="false" />
                </authentication>
            </security>
        </system.webServer>
    </location>

This solved the issue with Media items. 

09 July, 2012

How to use custom font in Sitecore

Different browsers will use different font types for using custom font in HTML. From the blog, we can understand the compatibility of different font types in various browsers.

Font Type
IE
Mozilla
Safari
Chrome
Opera
.ttf
No
3.5+
3.1+
2.0+
10+
.otf
No
3.5+
3.1+
No
10+
.eot
4+
No
No
No
No
.svg
No
No
3.1+
0.3+
9.0+
.woff
No
Yes
???
???
???
                     .ttf – All browsers which are compatible to CSS3.

All the font types may be having same name. 
@font-face
{
    font-family: 'Brandon';
    src:      url('/~/media/css/fonts/Brandon.eot') format('embedded-opentype'),
              url('/~/media/css/fonts/Brandon.woff') format('woff'),
url('/~/media/css/fonts/Brandon.ttf') format('truetype'),;
}

For example: Brandon.ttf, Brandon.otf, Brandon.eot. If we upload all the types in 
same folder as like the below screenshot and when we request for ‘eot’ extension, 
it may download any of the font-type or same. Mostly it will download the first 
item in the folder. This is not consistent.  
 
 When I tested with the below url, http://sample/~/media/css/fonts/brandon.eot, 
it downloaded woff font type. 
 

So ideally the above CSS should be able to download the font depending upon the extension 
and the browsers.  
Few hacks and ideas: 
1.       Rename the font file name for each type, upload it in Media library and use it 
in CSS src attribute. Then the requested url should be able to download the font as 
we will be having one font in each type.
                  
 Also add the following mime type for the font. 
Font Type
Mime
.ttf
font/truetype
.otf
font/opentype
.eot
application/vnd.ms-fontobject
.woff
application/x-font-woff
2.       In IE9, you may get error “@font-face failed OpenType embedding permission check. 
Permission must be Installable.” Fix: “Obtain the correct permission or licenses for 
embedding the font.” 
– Source: http://blog.beacontechnologies.com/custom-fonts-i-internet-explorer/ 

If anyone has solution to request multiple font types with same file name in Sitecore, please comment and provide me the solution. 
blockquote { margin: 0; } blockquote p { padding: 15px; background: #eee; border-radius: 5px; } blockquote p::before { content: '\201C'; } blockquote p::after { content: '\201D'; }