• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 369
  • 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
0
rocketdoctor
Asked:
rocketdoctor
2 Solutions
 
justinbilligCommented:
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.
0
 
jawahar_prasadCommented:
in global.asa

sub application_OnStart
application("totalcount")=0
end sub

Write the following code in your home page :

if trim(session("mycount"))="" then
 session("mycount")=1
 application.lock
 application("totalcount")=application("totalcount")+1
 application.unlock
 if application("totalcount")>10 then
  response.redirect("anotherwebsite.com")
 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
application.lock
application("totalcount")=Application("totalcount")-1
application.unlock
end sub


Thanks
Jawahar Prasad
*** advertising removed by Netminder ***
0
 
fozyletCommented:
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
  Application("TotalCount")=0
End Sub

Sub Session_OnStart
  Application.Lock
  Application("TotalCount")=Application("TotalCount")+1
  Session("MyCount") = Application("TotalCount")
  Application.Unlock
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.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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