Monday, January 23, 2017

WFFM: Save to Database

Web Forms For Marketers has become one of the essential component of Sitecore. Almost every website is using forms to capture the inputs from users and it is very common scenario to get the data stored in Database for reporting purpose. Here are few easy steps which can help you storing the form's data in SQL database.


  1. Download the WFFM - SQL Provider(Save To Database) and install it in Sitecore using Installation wizard. All physical files and Sitecore items will be stored in respective location.
  2. Once installed, you will notice that it has created a new Action under System-> Modules -> Web Forms for Marketers -> Settings -> Actions -> Save Actions
  3. Now, we have to add connection string in configuration file which will help us storing the data in that database. You have to keep the name of connectionstring to 'wfm' only as same name is referred in WFFM module code.

< add connectionstring="user id=your_db_user_id;password=your_db_password;Data Source=your_db_server;Database=your_db_name" name="wfm" >

You are done.

Now add the 'Save to Database' action on any WFFM form and start using it. Also validate the database and data should start getting stored in it.

Furthermore, this module provides the capability of exporting the saved data in CSV format. We can do customization on it to export the data from different servers(CMS or CD) which I will explain in next article.


Please don't hesitate to contact me at 'email.bajaj@gmail.com' for any Sitecore related query/scenario.

Wednesday, June 8, 2016

HTTP Compression and Performance tuning

With the advancement of technology and exceeding expectations of users, one has to be very careful designing a website. Performance is one of the key elements for success of an application. Even if, you have designed the application with uttermost care and rock solid architecture, there are few key areas in which you have to be really vigilant. HTTP Compression is one of those pivotal spaces.

HTTP compression is the technique to compress static and dynamic content which improves the transfer speed and performance of a website.

Steps to keep the compression ON for a website. Here the demonstration is given for IIS based website.
1. Open IIS (inetmgr)
2. Goto website. Right side will show all components of that website
3. Click on 'Compression' module and verify that both the checkboxes are checked if you need static and dynamic content to be compressed.




4. Click 'Mime Types' and check 'application/x-javascript' is added in the existing mime types. If not, add it.
5. Reset IIS, browse website and verify that JS is getting compressed now.

Web.Config Settings
Here are all the mime types and gzip information which should exist for a website if compression needed, either in IIS settings or in web.config.
Note: Include it in web.config if configuration file also get deployed with every build.

Section to include in <system.webserver></system.webserver>
<system.webServer>
<httpCompression> 
  <staticTypes> 
    <add mimeType="text/*" enabled="true" /> 
    <add mimeType="message/*" enabled="true" /> 
    <add mimeType="application/javascript" enabled="true" /> 
    <add mimeType="application/x-javascript" enabled="true" /> 
    <add mimeType="image/jpeg" enabled="true" /> 
    <add mimeType="*/*" enabled="false" /> 
  </staticTypes> 
  <dynamicTypes> 
    <add mimeType="text/*" enabled="true" /> 
    <add mimeType="message/*" enabled="true" /> 
    <add mimeType="application/javascript" enabled="true" /> 
    <add mimeType="application/x-javascript" enabled="true" /> 
    <add mimeType="image/jpeg" enabled="true" /> 
    <add mimeType="*/*" enabled="false" /> 
  </dynamicTypes> 
  <scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" dynamicCompressionLevel="4" /> 
</httpCompression>
</system.webServer>

After compression is ON:
Response header of a JS file being loaded in website. 'Content-Encoding: gzip' shows that it is compressed.



Useful tools
There are several webistes which can help you detect, if your website/CSS/JS is compressed or not. You should check css/js or website seperately to make sure that all static medias are compressed. One of the examples website is given here.
Check Compression

For further detail, you can contact me www.bajajsumit.com. Please share your feedback if you find the article useful.

Thursday, April 14, 2016

Running dotnet on Linux

Server: Linux, version SUSE 12

To run dotnet code on Linux, the first and foremost task is to "Install Mono package on linux".

Note: Mono is an open implementation of Microsoft's .Net framework, including compilers. It uses the same development libraries on Linux which are being used on Windows. Therefore, if you code and compiled some mono code on Linux,  it will work for Windows as well.

      zypper is a package installation tool which is used in this scenario. If zypper is not available, check which package manager tool is installed on server. Furthermore, to verify if zypper is installed or not, type zypper on command line which will show all options if zypper is available on server else it will show 'command not found'.

zypper ar -r http://download.opensuse.org/repositories/Mono/SLE_11_SP2/Mono.repo

The above command will download from mentioned URL in a new repository. Here 'ar' stands for 'add repo'.

After adding it to repository, type 'zypper refresh' command, it will ask to install packages. Type the appropriate option and install the Mono packages.


Once successful installation,       we are all set to run dotnet on linux server.

Running first dotnet code

Create a new test.cs file by typing following command.

$cat>test.cs

Now open the file using any available editor. In this case it is 'vi' editor.

vi test.cs

Starting writing the first dotnet code as shown below.

      Information about 'vi' editor:
  • Type 'i' to change it to insert mode.
  • Type 'esc' to come out of insert mode.
  • Type ':w' to write the file and save.
  • Type ':q' to quit and come back to command line tool.

       NOTE: If any exception appears like '!' is required to override the file. Type ":w!" to override the existing file and write the new text. OR Type ":q!" to override the existing file with new text and quit.

C# code for 'test.cs':
using System;
namespace Test1
{
class Test1
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!!");
}
}
}

Once you have saved the file, its time to compile it. 'mcs' is command which is used for compiling the code.

dev-server-linux-suse12:~ # mcs test.cs

After compilation is successfully completed, its time to run the application. As it is console project, '.exe' file will be created as output. 'mono' is the command used for running the test project.

dev-server-linux-suse12:~ # mono test.exe
Hello World!!

You are all set to run dotnet on Linux. Provide your valuable comments/suggestions.

Tuesday, March 22, 2016

Cannot alter the login 'sa', because it does not exist or you do not have permission.

Working on projects, it can happen that 'sa' account gets locked. If it is on local machine OR development boxes, onus would be on you to fix it. If scripts and SQL steps are not working, this might help you fixing the issue.

Steps to unlock 'sa' account and resetting the password.

1. Open SQL Server Configuration Manager

2. Select SQL Server Services -> 'SQL Server' service.
3. Right click on 'SQL Server' service and click on "Startup Parameters". For 2008, server "Startup Parameters" are inside Advanced tab.
 

4. Add '-m' in startup parameters as shown above and click on 'Add'. This will put SQL server into 'Single User Mode' and local admin will have 'Super User' rights. For 2008, server you have to add ':-m' in the last of the existing query.
5. Save the settings and Restart the service.
6. Now open the SQL Server Management Studio and connect to database using 'Windows Authentication'.
7. Goto Security -> sa -> Right click and open properties.
8. Unlock the 'sa' account and reset the password.


YOU ARE DONE!!

**Important: Now to switch back to 'Mixed User Mode' where you can access the database using 'sa' account, remove the '-m' from 'Startup Parameters' which we added in above steps.


Wednesday, February 10, 2016

Setting up web server and continuous integration

Apart from creating website & app-pool in IIS, there are several steps which need to be performed when setting a new website on server.

Setup Web Server

There are few activities which you have to perform on Web Server:
1. Install Web Deploy [Download]
2. Install URL Rewrite [Download]
3. Make Sure .Net Framework feature is ON in Windows features


4. Create a standard user which could be used to deploy files to web server after successful build
5. Open "services.msc" and check that 'Web Deployment Agent Service' is running with the standard user credentials created in Step 4.


6. Run App pool and website with same standard user which is created in Step 4
7. Reset IIS Server


Continuous Integration

There are several tools which are being used for continuous integration but they perform same functions when we discuss about build and deployment. In this example, we are referring Jenkins [Download].



If msdeploy or any relevant command is being used to deploy files on web server, same standard user credentials should be used to copy the content else it will throw unauthorized exception.

Common Exceptions

An item with the same key has already been added.
Solution: It can be resolved by checking Mime types. There is a probability that same Mime type is being added by web.config which is there in IIS already. In IIS 8, there is not need to add Mime types manually.

Website is appearing but css/font is not loading.
Solution: Open dev tools(if its chrome browser, press F12 key) and check if in console you are getting errors like 404, 500 etc. Check if css/font files are present in the right folder. If gulp or grunt is being used, make sure it is compiling the files without exception.

If any CMS is being used then there might be CMS related errors.

Sitecore has no necessary permissions for reading/creating counters. OR 
Sitecore publishing screen is showing 'Initializing' but not publishing anything.
Solution: Application pool user should be member of 'Performance Monitor User' group. Add user to this group and restart IIS. Even after this, if it does not work sitecore counter can be disabled by setting counter value to false. For example: <setting name"counters.enabled" value-"false"/>

Let me know if you still get any exception. Have a nice day!!

Wednesday, January 13, 2016

Get all Items inheriting another template

Working on different templates and Sitecore items, its very common requirement to know

  • how many items are created with a specific template
  • how many template are inheriting a base template or another template

Sitecore provide this feature out of box however you need to write query to fetch the required items.

  1. Open Sitecore IDE (http://localhost/sitecore/shell/default.aspx?xmlcontrol=IDE)
  2. Goto Tools -> XPath Builder
  3. Write XPath Expression:

/sitecore/templates//*[contains(@__Base template,'{1FE1328B-375B-4548-A53E-344FA61ACC90}')]



In result section, it should show all templates which are inheriting base template with ID {1FE1328B-375B-4548-A53E-344FA61ACC90}.

Similarly, query 
/sitecore/content//*[@@templatename='Promotional Page'] should show all pages (under content) created with 'Promotional Page' template.

On top of results, it shows the count of items and time taken to fetch the items.

We can use fast query as well instead of query.

Note: The above queries are example of specific requirement. Query can be modified to get required items according to project need.




Friday, August 14, 2015

Sitecore - Moving items from web to master

In most of the cases, generally you create items in master database and publish to web/production data. However, sometimes few items are in web database and not in master. Reason can be anything, like you might have deleted it in master but did not publish the parent item or due to some other reason.

If you are thinking, you will create package from web and deploy it in master, that will not work. :-) When you create package from master, it installs the items in master only and same is the case with web.

Right and easy way to do is Transfer the item. Yes, you read it right. There is a provision in Sitecore to transfer the items from one database to another.

Select the item which you want to transfer from one database to another. Right click on it and then select Copying. Click on Transfer. see screenshot



Once you click on Transfer, it opens up a popup box. Click 'Next'. see screenshot


After clicking on next, you have to choose the database where you would like to transfer the item. In this case,master database is selected. see screenshot

Select the folder where you want to transfer the item on master database(in this case). Click 'Next' and it will transfer the item to master database.

If you like the blog, kindly put your comments. You can write email to support@bajajsumit.com for any Sitecore or .Net related help.