Creating link with click counter and other server-side logics.

Overview

I know many cases when you need to create a smart or say rich link on a page. Rich links are links that can first execute some logics and than send user to desired location. What kinds of logics are common for rich links:
  • Count clicks, provide extended statistics;
  • Hide actual URL;
  • Determine actual URL after user clicked the link.
There are 2 main methods of providing such links
  • Javascript page submission
  • Redirect link (like Linkclick.aspx)
Here I’ll show how to implement these methods using XsltDb.

Method 1. Page Submission


<xsl:if test="mdo:param('@golink')">
  <xsl:variable name="prm1" select="mdo:param('@prm1')"/>
  <xsl:variable name="prm2" select="mdo:param('@prm2')"/>
  <!--
     here we perform logics, increment click counter and build a real URL to redirect a user
  -->
  <xsl:execute select="mdo:redirect('... link that you build goes here ...')" />
</xsl:if>

<a href="{mdo:jsubmit(
   '@golink', 'some linke data',
   '@prm1', 'prm-1-val',
   '@prm2', 'prm-2-val')}">Go to some link</a>
In this method we use a mdo:submit to submit a page and mdo:redirect to move user to desired page. This method initiates a new cycle of complete ASP.NET page and may be inefficient in case of heavy business logics on a page.

Method 2. Redirect Link Handler

XsltDb allows you to create a service that is accessible by parameterized URL can be executed outside of current page context.

<mdo:service name="redirector" type="text/html">
  <xsl:variable name="link" select="mdo:request('golink')"/>
  <xsl:variable name="prm1" select="mdo:request('prm1')"/>
  <xsl:variable name="prm2" select="mdo:request('prm2')"/>
  <!--
     here we perform logics, increment click counter and build a real URL to redirect a user
  -->
  <xsl:execute select="mdo:redirect('... link that you build goes here ...')" />
</mdo:service>

<a href="{mdo:service-url('redirector')}&amp;golink=some+link+data&amp;prm1=prm-1-val&amp;prm2=prm-2-val">Go to some link</a>
Here we use mdo:service to create an XsltDb HTML service that actually don’t return any HTML but executes required logics and redirects user to desired URL. Having mdo:service tag inside configuration we can obtain a link to the service by using mdo:service-url extension. After that wa just add out parameters to the end URL returned by mdo:service-url and create a simple link on the page.

Last edited Sep 4, 2010 at 11:08 AM by findy, version 7

Comments

No comments yet.