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 ?
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;
}
}
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.