Surendra Sharma

Surendra Sharma

Search This Blog

Tuesday, June 16, 2015

Sitecore website Session is expiring after 2-10 min


I was working with one Sitecore 7.5 website where session is expiring problem is occurring. This is happening in all browsers. The issue was strange as normally ASP.NET maintain session for 16 minute by default.

I was keeping some website related information in Session.

·         I have set session for more than 60 minutes in web.config file but session is expiring after 2-10 minutes. (sporadic behavior)

·         The problem is also occurring even when site is not idle. (again sporadic)
I have checked the Sitecore log files and saw some suspected messages which may be pointing to this problem

·         Overriding expired contact session lock. This typically means the previous request for the contact did not release session state properly or is taking too long to execute.
·         WARN  Overriding expired contact session lock for contact id: c855c633-7974-44a8-b436-6da08dc1743e

Solution:

Disable Analytics Robot Detection by setting value false in 'Sitecore.Analytics.Tracking.config' as:
<setting name="Analytics.AutoDetectBots" value="false" />


Please leave your comments or share this tip if it’s useful for you.

Friday, June 12, 2015

The Sitecore App Center password is not set.

If you are working with Sitecore 8 EXM [Email Campaign Manager] module then you might get error The <a href='/sitecore/shell/Applications/SitecoreApps/Loader.aspx' target='_blank'>Sitecore App Center</a> password is not set.

What this message suggest and how to fix it?

If you are using custom mail server instead of Sitecore App Center then you need to set the “UseLocalMTA” as “true” in Sitecore.EmailCampaign.config with SMTP details.

However due to “Sitecore.EmailCampaign_old.config” file, your all these settings will be blank. You can check related message in log file as A duplicate setting "UseLocalMTA" has been detected in the Sitecore.EmailCampaign_old.config file. The value of the setting will be changed to "false".

Solution: Just delete the Sitecore.EmailCampaign_old.config file for fixing this issue.


Please leave your comments or share this tip if it’s useful for you.

Friday, June 5, 2015

How to check occurrence of 404 errors on any web page


It’s always great to avoid any 404,500 errors in your web site. There are several tools available for testers to find out the 404 and 500 errors in whole website. But what about developers? Do we know any tools for it? Actually we never bothered about it because we are programmersJ.

But still folks, there are some easy ways in browsers itself where we can find out the 404 and other errors list.

Chrome
Right click on web page -> select 'Inspect Element' -> select 'Console' tab.

Mozilla
Right click on web page -> select 'Inspect Element with Firebug' -> select 'Console' Tab -> ‘Errors’ tab.

Please leave your comments or share these tips if it’s useful for you.

Friday, May 29, 2015

Best SEO practices for ASP.NET Sitecore projects

If you developing any web applications, your client expect to implement SEO techniques. Here I am specifying some of the useful techniques that should be part of any website.

1.    Meta description and keywords

Add Meta tags for description and keywords in Head section.

<meta name="description" content="Put your description here" />
       <meta name="keywords" content="keyword1, keyword2, keyword3" />

2.    Authority Transfer

Do a 301 redirect to all important pages from old website.

3.    Poor URL Structure:
·         The URL’s should be in lower case
·         There should be no extension in URL like .aspx
·         There should be no spaces in the URL’s
·         Dash(-) sign should replace any spaces in the URL’s

4.    Custom URL provision:

There should be a provision to edit the URL for every page in the Sitecore admin.

5.    301 redirect provision:

Provision for 301 redirect on every page to do redirection from old URL to New URL.

6.    Default Title tags:

H1 tags should be used as default title tag for the page

7.    Open graph tags for Social media:

Implement basic og tags for social media like

·         Title
·         Description
·         URL
·         Image
·         Type

Here is example for this
<head>
<title>The Rock (1996)</title>
<meta property="og:title" content="The Rock" />
<meta property="og:type" content="video.movie" />
<meta property="og:url" content="http://www.imdb.com/title/tt0117500/" />
<meta property="og:image" content="http://ia.media-imdb.com/images/rock.jpg" />
</head>

Refer http://ogp.me/ for more details

8.    Canonical tag element

There should be a provision for adding canonical URL in every page. By default the current page URL will be used.

Here is the syntax:
<link rel="canonical" href="http://www.yourwebsite.com/">

Please leave your comments or share these tips if it’s useful for you.

Tuesday, May 19, 2015

Different ways to generate unique ID in C#

In every project we need to generate some id which should be unique. I was just wondering what are the options available in .NET to achieve this?

One can go for GUID as it’s a 128 bit integer long.

       Console.WriteLine("GUID = " + System.Guid.NewGuid().ToString());
       //Output - GUID = 54f6461a-59f4-4f9f-9a67-49b18ebc6eb6

This seems to be perfect but check GUID is alphanumeric. What if we anybody want only numbers. Holy shit.

We can use random class for it as

Random random = new Random();
Console.WriteLine("Random = " + random.Next(int.MaxValue).ToString());
       //Output - Random = 1344254902

But random class has limitation of max value of integer. It can generate only 10 digit long number. Probability of generating the duplicate number is high with Random class.

Is there any other option?

Interestingly we have datetime available in C#. We can get date as well as time and can generate long number.

Console.WriteLine(System.DateTime.Now.ToString("yyyyMMddHHmmss"));
//Output – 20150519190734

Its 14 digit long number now.

You say you want longer number than this. Don’t forget milliseconds placeholder. Most interesting part of millisecond is that it’s a 7 digit long. You can use millisecond from single f to 7 times f.

Console.WriteLine(System.DateTime.Now.ToString("yyyyMMddHHmmssfffffff"));
//Output - 201505191907346290105

Its 21 digit long number now which should be unique in its own way.
Don’t be greedy. Don’t try to write “f” more than 7 times otherwise you will get “System.FormatException: Input string was not in a correct format.” Error.

Come on buddy, 21 digits long number [Correct word for this is string] is enough for us.


Let me know if you know any other way to generate it.

Please leave your comments or share this code if it’s useful for you.

Saturday, May 16, 2015

How to fix 404 error for fonts in ASP.NET

My tester informed me that we are getting 404 for woff font file. I checked the presence of woff file in fonts folder. I checked the path of font file. Both these checks are positive and everything was seems to be correct. We were not getting the 404 error for any other font file except woff file. Then I googled it and come to know that people are already facing the same error for woff font file.

This is the problem of MIME type. So there are two ways to solve it.

·         IIS
·         Entry in ASP.NET project’s web.config file

Through IIS
          You to make MIME entry in IIS as below for this font

·         Run IIS Server Manager, Open Mime Types and add following
o    File name extension: .woff
o    MIME type: application/x-font-woff

Through web.config file

You can also add the entry of MIME types in the web config as follows

  <system.webServer>
    <staticContent>
      <remove fileExtension=".woff" />
      <mimeMap fileExtension=".woff" mimeType="application/x-font-woff" />
    </staticContent>   
  </system.webServer>

I prefer the second option of web.config file as this file is a part of our project and we can change it at any time. But it’s very difficult to get the access of IIS on production or client environment.


Please leave your comments or share this tip if it’s useful for you.

Thursday, May 7, 2015

How to replace space by dash in URL in Sitecore

For the sack of SEO, it’s always a good practice to avoid any blank spaces in URL and replace them by dash (-).

It’s very easy to achieve this task in Sitecore. Just write below highlighted line just before closing tag of </encodeNameReplacements> in web.config file.

      <replace mode="on" find=" " replaceWith="-"/>
    </encodeNameReplacements>

That’s it. No programming needed.

You can use any other character also instead of dash.


Please leave your comments or share this code if it’s useful for you.