Updating database on each http request with ServiceStack

157 Views Asked by At

Assuming I want to keep track of LastVisited field in a DB and I want to update it on each incoming request whether its hitting a ServiceStack API or an MVC Controller. What would be the best way of handling it? Obviously I can put the logic in the Global asax which will run on each request, but how would I access the session object from ServiceStack? or is there a an http handler I can attach to where the ServiceStack's session is available.

1

There are 1 best solutions below

1
KennyZ On BEST ANSWER
protected override void OnActionExecuting(ActionExecutingContext filterContext)

and

protected override void OnActionExecuted(ActionExecutedContext filterContext)

These will override methods that are part of the System.Web.Mvc.Controller class.

We override this class with a base controller which all our controllers inherit from. You could use either of these for what you are asking.