Tuesday, March 13, 2018

Localization of Sharepoint Display template

There was requirement in our project where we need to localize the display template. Basically we have 5 different flavors of localization implemented  in our project.

In order to achieve this we have  come up with localizing the resource file with javascript implementation, which is quite interesting and new in sharepoint implementation perspective.


Below are the steps we need to follow to make sure localization can be implemented in display templates


 a) Come up with all localization text  and corresponding key value pair as like normal resource file.

 b) Create javascript file with your favourite editor such  as notepad, notepad++ etc with the below syntax


$registerResourceDictionary("en-us",
{"PageTitle": "Page Title",
"ProductName": "Product Name",
"ProductDescription": "Product Description"});


 c) Here we can all the resource file key value pair which needs to be displayed in the display template


 d) Save the file as ResourceFile.js

 e) Please make sure about the locale language which needs to be present in the 1st  line.
 f) Upload this file in style library and add the reference of this file in the display template as below  reference







g) The resource file needs to be present in all locale site collection style library with appropriate language else it will start throwing error.

h) Once all the above steps completed, then we need to access the resource key like this.
    var pageTitle = $resource("PageTitle");

i) We can use this in the variable in any of the place in the display template




Wednesday, March 7, 2018

Enabling Developer Dashboard in sharepoint 2013

Developer dash board is one the great feature introduced by Microsoft from sharepoint 2010 version, it got extended in sharepoint 2013 with little bit changes.

Now in this post I will explain how to enable Developer Dashboard in sharepoint 2013 environment.

Below are steps to enable:

1) Make sure Usage and Health data collection service is enabled or not, if its enabled then you can continue with step 3 else need to follow step 2

2) Enable Usage and Health data collection service please refer the msdn link

https://technet.microsoft.com/en-us/library/ee663480.aspx

3) There is no UI steps available to enable Developer Dashboard in sharepoint, so we need to depend only on PowerShell scripts:

4) Open sharepoint 2013 management shell as admin user

5) Run the following code snippet to enable the developer dashboard

$content = ([Microsoft.SharePoint.Administration.SPWebService]::ContentService)
$dashboardsetting =$content.DeveloperDashboardSettings
$dashboardsetting.DisplayLevel = [Microsoft.SharePoint.Administration.SPDeveloperDashboardLevel]::On
$dashboardsetting.Update() 


6) This will enable the developer dash board on the sharepoint site

7) The above steps work only for sites which are opened with intranet site with authenticated users, it doesn't work for anonymous web site. By default developer dashboard will be enabled for authenticated users  with RequiredPermissions set to AddAndCustomizePages

Note: After executing the step 5 if we enter $dashboardsetting in powershell console it will display the all the configuration done with Developer dashboard

8) To enable Developer dashboard in anonymous site we need to run the below script to make it available

$contentService = [Microsoft.SharePoint.Administration.SPWebService]::ContentService
$dashboardSettings = $contentService.DeveloperDashboardSettings
$dashboardSettings.RequiredPermissions = [Microsoft.SharePoint.SPBasePermissions]::EmptyMask
$dashboardSettings.Update()


Note:
a) Make sure Developer Dashboard html tags are available in the master page(in case if the master page is customized)
b) Usage and Health data collection service is up and running
c) I have verified developer dashboard for https site also with anonymous users(internet facing site) and its working without any issues.



HTTP to HTTPS redirection

In my current assignment I have created new web application under port 443(with host header site collection) and  enabled both anonymous and NTLM authentication.
And in IIS I have edited the bindings used certificate to make it https site.

Added DNS entry and  it was working as expected.

Ex: If the user browse the site https://test.abc.com its opening the site, but if the user enter

http://test.abc.com then it was not redirecting to my https site and also it was giving 404 error.

From url perspective what ever it was returning that was correct, since  there was no site hosted under port 80 and it was giving 404 error.

Later I thought I will use the IIS URL Redirect module which is available and setup the same in the environment, but it was not working as expected.

In order to fix this later I decided I will add new AAM in the web application under default zone with http url

ex: 

Here I have created AAM with default zone(even though there is default zone already present) with http://test.abc.com

Now bind that host entry in IIS web application like as below

Now we have all the entry for https and http (ignore the other 2 which I have created for my project purpose).

If the user now tries to browse the site with http it will redirect to https

Note:
My IIS application was created under port 443
Its binded with SSL and its extended web application