Redirect a percentage of traffic coming to page based on session

Posted on 2005-04-19
Last Modified: 2012-05-05
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
Question by:rocketdoctor
    LVL 15

    Expert Comment

    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.
    LVL 8

    Assisted Solution

    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 ***
    LVL 8

    Accepted Solution

    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("")

    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.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
    This demonstration started out as a follow up to some recently posted questions on the subject of logging in: and…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now