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.
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:
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, …).
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:
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”
You can download xml file, that you can use to import sample Task into Task Scheduler:
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.