Distributed Cache in SharePoint is very good, but after some time, its content becomes old. The first user who visits specific SharePoint Site, which was not visited for longer time, has to wait many seconds that Site Web Page opens, because Distributed Cache has to refresh its content. This is not optimal user experience and could be annoying.

 

Solution:

 

If I would like to solve the problem, I have to create a script that would run on schedule.

One option is to open specific Site Web Page in browser, but it is problematic, because in this case I have to run specific browser many times and script will probably fail on long run.

Better option is to use WebClient.DownloadString Method, which can download Web Page as string.

 

First of all I have to enable access to SharePoint Site from the same machine, where SharePoint is hosted. Windows Server has integrated loopback security feature that prevents me to access SharePoint Site from SharePoint hosted Server. I can enable access to SharePoint Site using Registry (regedit.exe).

I have to find registry key:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa\MSV1_0

and add registry Multi-String Value:

BackConnectionHostNames with all desired FQDN from which I want to access SharePoint Sites (for instance spca.contoso.com, sp.contoso.com, …).

 

BackConnectionHostNames

 

You have to restart SharePoint server to apply upper settings. SharePoint Sites from above list should be accessible using browser (Internet Explorer) on SharePoint server.

 

Next, I have to create PowerShell script (for instance OpenSP.ps1), that is needed to download Web Page as string:

$webclient = new-object System.Net.WebClient
$webClient.UseDefaultCredentials = $true
$webpage = $webclient.DownloadString(“https://sp.contoso.com”)

 

Above script should be run as user that has rights to open SharePoint Web Site (for instance Contoso\SPAdmin). User’s credentials will be provided while opening SharePoint Web Site.

You can’t provide specific credentials in script, because using Windows Authentication SharePoint Site will never authenticated specified user.

 

Save PowerShell script in Windows Folder (for instance C:\Scripts).

 

In the last step I have to create Task using Windows Server Task Scheduler.

Task should be run as user account that has rights to open SharePoint Web Site (Contoso\SPAdmin) and it should run whether user is logged on or not.

Task is triggered every hour indefinitely (you can select different scheduler).

In Task Action, I select to run a program: PowerShell.exe with arguments: -ExecutionPolicy Bypass “C:\Scripts\OpenSP.ps1”

 

Task Action

 

You can download xml file, that you can use to import sample Task into Task Scheduler:

Open sp.contoso.com.xml.

 

That’s all. Now users will not have problems visiting SharePoint Site anymore!!! 🙂 

 

You can use the same script to refresh different Web Pages, when you see that it could be useful.

mm
Written by Simon Abolnar
I am a lecturer of Informatics subjects at Higher Vocational College at the School Center Nova Gorica, located in Slovenia-EU. I have been a System Administrator of Microsoft Servers at SCNG for over 20 years.