Yes, you can intercept this in the controller for each request:
If you need the page that the user requested:
Request.RawUrl //Gives the current and complete URL the user requested
If you need the country from which it was requested, you can get the IP address of the user and then use the ready-made function to find where it is .
Request.UserHostAddress
You can also get all the route values ββthat the user has traveled; to get a better picture of how they got to where they are.
public class MyController : Controller { public ActionResult Home() { var userIP = Request.UserHostAddress; var requestedUrl = Request.UserHostAddress; var routeValues = this.ControllerContext.RouteData.Route.GetRouteData(HttpContext); var requestedDateTime = DateTime.Now; } }
Now you have to put it on every action, and it seems silly, so why not happen for everything that was done ?
protected virtual void OnActionExecuting( ActionExecutingContext filterContext) { var userIP = filterContext.HttpContext.Request.UserHostAddress; var requestedUrl = filterContext.HttpContext.Request.UserHostAddress; var routeData = ((MvcHandler)filterContext.HttpContext.CurrentHandler).RequestContext.RouteData.Route.GetRouteData(filterContext.HttpContext); var requestedDateTime = DateTime.Now; }
source share