• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 373
  • Last Modified:

Redirect a percentage of traffic coming to page based on session

I want to redirect 10% of traffic coming to a specific page to another site.  I want to make sure this happens on a session level basis only so if some one comes to the site and refresh the page this should not count as a second hit.    I am familiar with setting up applciation level variables to count and then redirect based on the value but how do I increment the count on a unique session base only
2 Solutions
you would have to use application_onstart / application_onend, you would then count each time a new person begins the application ( before the session is actually created ).

But I do believe you can set up your server to do the load balancing.
in global.asa

sub application_OnStart
end sub

Write the following code in your home page :

if trim(session("mycount"))="" then
 if application("totalcount")>10 then
 end if
end if

Explanation :

    The first time when a user opens your page then if checks for session variable mycount, Initially it will be empty, so a value of 1 will be stored. and the application("totalcount") will be incremented by 1.  

   Then it checks if the totalcount>10 , if yes then it redirects to another page

IMPORTANT : we also have to check if the session ends and the traffic reduces in the first site, we have to allow the traffic at the first site(your site) so  add this in global.asa

sub Session_OnEnd
end sub

Jawahar Prasad
*** advertising removed by Netminder ***
If you have a DB-based log, adding an identity column to it and sending every 10th person to another page is a possible solution.

What jawahar suggested is viable in principle too. Juz making some improvements...

Sub Application_OnStart
End Sub

Sub Session_OnStart
  Session("MyCount") = Application("TotalCount")
End Sub

Now, in the particular pages where you want to implement this load balancing
  If Session("MyCount") Mod 10 = 0 Then Response.Redirect("anotherwebsite.com")

That should do it. You should not be decreasing the count since that would give you 10% of current visitors (at best) and not 10% of traffic. Also, this will fire only once per session. Backing up the count to session is important since app counter is bound to change with each visitor.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now