Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

the previous page of the user

Status
Not open for further replies.

davikokar

Technical User
May 13, 2004
523
IT
hallo,

For example: I am in the page A of my web application, then I click a link and navigate to page B. Now I click a linkbutton in page B. Is there a way to know that the user that pushed a button in page B, came from page A ?

Thanks for advice
 
You will only know what page the user came from on the first hit of PageB. (Request.URLReferrer). Once you hit a button on Page B, it causes a post back, and the Referrer is now Page B.
 
to track this you would need to implement a custom logging solution to track each url hit and the order they happened. building it is easy enough with an audit table and http module.
Code:
audit_trail (
   Id bigint not null,
   SessionId varchar(1000) not null,
   Url varchar(1000) not null,
   Referrer varchar(1000) null,
   User varchar(50) not null,
   VisitOrder bigint not null,
   DateOfVisist datetime not null,
   primary key (Id)
)
Code:
public class AuditTrail : IHttpModule
{
    public void Init(HttpApplication context)
    {
        context.BeginRequest += LogVisit;
    }

    public void Dispose(){ }

    private void LogVisit(object sender, EventArgs e)
    {
          var context = HttpContext.Current;
          var sessionId = context.Session.SessionID;
          var url = Context.Request.Url.ToString();
          var referrer = Context.Request.UrlReferrer.ToString();
          var user = Context.User.Identity.Name;
          var visit = DateTime.Now();
          var visitOrder = GetNextVisitIncrement();

          //now save this data back to the database.
    }

    private long GetNextVisitIncrement()
    {
         //query database
         select top 1 VisitOrder from audit_trail where [User] = @user order by VisitOrder desc;
         // map row to Visit object and return
         if(no rows exist) return 1;
         return Convert.ToLong(row["VisitOrder"])+1L;
    }
}

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
faq732-7259
 
it should go without saying, but just incase... you could then use this table to query for "previous" page.

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
faq732-7259
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top