Page load globar event

Targutai Yesugei asked on April 4, 2018 12:42

Hello!

Can't find global event for page loading event to get some info from http request. For tracking document insertion event i'm using DocumentEvents.Insert.After += Document_Insert_After; So, looking for something similar.

I found this , but when using this namespace, i can't find anything like CMSPages.OnBeforePageInit.

Thank you in advance.

Recent Answers


Dragoljub Ilic answered on April 4, 2018 13:36

Hi Targutai,

I'm not sure what you really try to accomplish here, but if you want to use 'CMSPages' events, they are place in the 'CMS.UIControls' namespace:

CMS.UIControls.CMSPage.OnBeforePageInit += CMSPage_OnBeforePageInit;

But this will work only for CMS administration pages. If you want that info on public pages, maybe you should consider to use custom macro and place it on master page (depends what info you need).

Best regards, Dragoljub

0 votesVote for this answer Mark as a Correct answer

Peter Mogilnitski answered on April 4, 2018 13:45 (last edited on April 4, 2018 15:09)

You kinda answering yourselft to your question:

using System;
using CMS;
using CMS.DataEngine;
using CMS.UIControls;

// Registers the custom module into the system
[assembly: RegisterModule(typeof(CustomInitializationModule))]

public class CustomInitializationModule : Module
{
    // Module class constructor, the system registers the module under the name "CustomInit"
    public CustomInitializationModule()
        : base("CustomInit")
    {
    }

    // Contains initialization code that is executed when the application starts
    protected override void OnInit()
    {
        base.OnInit();
        CMSPage.OnBeforePageInit += Before_Page_Init;
    }

    private bool Before_Page_Init(object sender, EventArgs e)
    {
        var referrer = HttpContext.Current.Request.UrlReferrer;
        var userAgent = HttpContext.Current.Request.UserAgent;
        // ...
        return true;
    }

}

P.S. I think you kinda looking for something to run code on any request i.e. global event on any request. You might take a look at this answer

0 votesVote for this answer Mark as a Correct answer

sachin khanna answered on April 19, 2018 12:01

I'm not sure what you really try to accomplish here, but if you want to use 'CMSPages' events, they are place in the 'CMS.UIControls' namespace:

Sachin Khanna

ECricketGames | Cricket Games | EA Sports cricket 2018

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.