INTRODUCTION
I’m developing a Sitecore website for a client where using Angular and WebApi. One of the functionalities is to ensure that search keyword is tracked in Sitecore Analytics. All sounds simple and straight forward, except the Tracker code requires Session to run. And since the code that tracks the keyword is inside your WebApi, it makes it even trickier.
Session is by default not enabled in generic WebApi let alone Sitecore’s one. A great article has been written to allow you to do this:
http://blogs.perficient.com/microsoft/2016/11/sitecore-add-session-to-web-api/
It all works fine except every time you want to use this functionality on different projects, you have to copy/paste the code and redo all over again.
I’ve managed to wrap it into a Sitecore package which you can deploy to various Sitecore websites. A configuration file has also been created so that you can add multiple WebApi controllers without having to change the source code.
HOW TO USE
1. Go to Sitecore Desktop > Installation Wizard and install the SitecoreSessionApi-1.0.zip
2. Go to your Website folder > App_Config > Include > zzzzSitecoreSessionApi and open SitecoreSessionApiConfiguration.xml.
3. Add all your WebAPIs that require session enabled.
<Api>
<Name>AdvancedSearchSitecoreSessionApi</Name>
<RouteTemplate>sitecoresessionapi/advancedsearch</RouteTemplate>
<ControllerToLoad>Search</ControllerToLoad>
<ReadOnlySession>false</ReadOnlySession>
</Api>
<Api>
<Name>MyOtherApi</Name>
<RouteTemplate>sitecoresessionapi/myotherapi</RouteTemplate>
<ControllerToLoad>MyOtherApi</ControllerToLoad>
<ReadOnlySession>false</ReadOnlySession>
</Api>
4. Finally, in your Angular code, to load the WebApi, instead of using /api/[controllername] URL you would use the URL you specify in the RouteTemplate variable above eg. /sitecoresessionapi/myotherapi
DOWNLOAD
Click here to download the package.
That’s it! Hope this helps.
Tommy
We provides you the best Services in our themes.
Click on the link below to see a full list of clients which we have developed solutions and provided consultancy for.
We are solution-centered and not application-centered.
Being creative and having fun and yet still delivering a fantastic service is the center of our values.
TFS Consulting Services guarantees delivery that is within budget and deadline or you engage us for free.
Implementing IT solution does not have to be difficult. TFS Consulting Services has a lot of resources on planning and methodologies that will ensure successful delivery of your IT solution. TFS Consulting Services has been around in the web industry for more than 10 years and has experienced all the successes and failures of various type of IT deployment.
Do you need a technical resource? TFS Consulting Services can also provide you with technical resource for developing ASP.NET (C# and VB.NET), SharePoint (2003, 2007, 2010, 2013) and MS CRM applications. Our resource is an Microsoft Certified Personnel (MVP) and Microsoft Certified Technology Specialist (MCTS) in all ASP.NET, SharePoint and CRM.
Make sure your IT implementation is robust and scalable. TFS Consulting Services can provide consulting and advice on industry’s best practice on various web-related areas such as website security, design and usability, application-specific (such as SharePoint)’s best practice, Search Engine Optimisation (SEO), coding standards and many others.
Finally TFS Consulting Services provides you with solution development service. We mainly work with Microsoft technologies (ie. .NET and SQL Server), however we are also capable of developing with PHP and MySQL. If you ever need any business process automation, integration and solution development work, we are the trusted expert you should go to.
For more detailed service offerings please visit our Solutions page.
Tommy Segoro
tommy@tfsconsulting.com.au
+61 404 457 754
© TFS Consulting Services 2024. All rights reserved.