Track last 5 or 10 visited products like shopping ites in as
Can any one plz help me with the code snippet, i need to track last 5 or 10 visited product on my site, how can i achieve this? if anyone have any kind of code snippet regarding then plz post..Thank you.

Wim SturkenboomPosted Sep 15, 2014, 1:00 PM
namespace WebApplication1
{
public partial class LastItems : System.Web.UI.Page
{
///
/// list with IDs of last items
///
List
protected void Page_Load(object sender, EventArgs e)
{
// read lastitems from session
g_lstLastItems = Session["LastItems"] == null ? new List
if (!IsPostBack)
{
// display last items
displayLastitems();
}
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
// make space for new item
if (g_lstLastItems.Count == 5)
g_lstLastItems.RemoveAt(0);
// random number to simulate
Random rnd = new Random();
// add 'new' last item to list
g_lstLastItems.Add(rnd.Next(1, 101));
// update session variable
Session["LastItems"] = g_lstLastItems;
// display result
displayLastitems();
}
///
/// display
///
private void displayLastitems()
{
tbLastItems.Text = "";
for (int cnt = 0; cnt < g_lstLastItems.Count; cnt++)
{
tbLastItems.Text += String.Format("{0} ", g_lstLastItems[cnt]);
}
}
}
}
g_lstLastItems holds a list of IDs of the last items. When the page is loaded, it is filled with the values stored in the session variable and the last items are displayed
I've used a button click to simulate the user viewing a certain item. The item is identified by a random number (you can use the real IDs of the items).
If a limit is reached (5 items in the example), first make space in the list, next add to the list, update the session variable and display the result in a textbox.
Instead of IDs, you can store strings containing a complete URL for an item or whatever. You can also consider use of a HashSet instead of a List; in that case there will never be a duplicate in the 'list'.
Ankur JainPosted Sep 17, 2014, 8:06 AM