1. Application events (scripts)

    Article: AN0002156Updated: 14.12.2018

    Application events enable to respond with a script to application start, user logon and other events.

    Event Application start

    This event is triggered after application start and its initialization. At this moment everything is already configured and models are loaded.

    It can occur several times during the day - every time when you or ISS restarts the application. The event is triggered also by changing file web.config or after creating and deleting file app_offline.htm.

    This example shows how to set routing in this event (taken over from model Version Controlled Documentation).

    var m = OG.Model.GetByCode('vcd');
    var cp = OG.ContentPage.GetAll().GetByCode(m.Id, 'article');

    var r = OGRoute.Create('vcd_an_v', 'vcd/{lang}/an/{an}/v/{version}', '~/WebContentpage.aspx');
    r.AddPar( 'id', cp.Id.ToString());
    r.AddPar( 'version', '');
    r.AddPar( 'lang', '');
    r.Use();

    Event User logon

    This event is triggered for every user when he or she displays ObjectGears system in the browser. At this moment session is created and event is triggered.

    Event Error occurence

    This event is triggered after every occurrence of an error. You can use the event to process the error, redirect to another page etc.

    This example shows responding to an error by redirection to another page. The example is taken over from model Version Controlled Documentation, where the original documentation was on page Help.aspx. in the new version the documentation is on address VCD/en-us/... In order everything works also for requests coming from older application versions and referring to the original address, we have to perform redirection. There is also indication for a permanent redirection (OGErrorInfo.RedirectPermanent). This should be done in order search engines do not penalize you for request redirection.

    if ( OGErrorInfo.IsInvalidPage && OGErrorInfo.Request.Url.AbsolutePath.ToLower().Contains('help.aspx'))
    {
    OGErrorInfo.RedirectPermanent = true;
    OGErrorInfo.RedirectToUrl = './vcd/en-us/' + OGErrorInfo.Request.QueryString['h'] + '/v/1.7.1.0/';
    }

    Event Web request

    This event is triggered at each web request. At the moment of the event triggering the user is not yet authenticated.

    The below example shows redirection of the user from www.myaddress.com to www.myaddress.com/vcd (from the default page to VCD). The default page of the Objectgears system is page default.aspx. The example is taken over from model Version Controlled Documentation

    //redirection from default.aspx to VCD
    var url = System.Web.HttpContext.Current.Request.Url.AbsolutePath.ToLower();
    if (url == '/' || url == '/default.aspx')
    {
      System.Web.HttpContext.Current.Response.Redirect( OG.GetWebUrl() + 'vcd');
    }

×