Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
I have a requirement to hack into the page load of each page request as it loads to the front-end.
When a user visits a page I need to hack into the loading or loaded event so I can log some extra stats into a custom database table I have created.
I will need to access what page is been loaded.
Ideally I would want access to the node Id or guid. Failing that just access to the url that is been loaded would work.
I understand about Routing hijacking but this is not really what I want. I don't want to have to create a controller for each doc type plus.
I literally only want to hack into every page request in one place, collect information about what page has been loaded and log this in the database. All other routing and rendering should continue through its usual path.
I am just wondering if there is any page loading or event I can override, capture the page data, log my stuff to the database, then continue the user on their normal path?
If you are wondering why I want to do this then it's for a basic page stats content app I want to build. Something very very simple which does not rely on analytics. It's a cool feature one of my lager e-commerce projects will benefit from plus I thought it might sit nice as a ContentApp.
Have you considered creating a static class that is executed in the master layout?
StaticClass.MyMethod(Model.Id, param1, param2)
<html itemtype="http://schema.org/Organization" itemscope="">
Yes i have. That's my plan b.
I plan to release this as a ContentApp so I really wanted my logic happening server side so I can compile this in a dll. I kind of want to save the user having to mess around with any extra front-end config if I can.
By default, Umbraco will execute every request via its built in default RenderMvcController. It is possible to change this behavior. You can create your own controller that inherit from the default RenderMvcController. In this controller you can override the index method and log the desired extras.
Use a Composer to change the default RenderMvcController to yours like so:
public class SetDefaultRenderMvcControllerComposer : IUserComposer
public void Compose(Composition composition)
See also the documentation at:
Awesome. I will take a look at this now.
Other option to consider is handling the Prepared Event of the PublishedContentRequest:
Essentially 'just' before the page is rendered, the Prepared event is thrown, and you can handle the event to gain access to the content and information about the request that is about to be rendered... and perform your additional logging...
... but by writing to the database with this approach and the custom RenderMvcController event will slow down the time it takes to render each page from Umbraco...
Great I will take a look at this.
This sounds like exactly what I need.
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted