Please enable JavaScript to view this site.

Navigation: Advanced topics > Events > Global events

Events.After application initialized

Scroll Prev Next More

Description

The AfterAppInit event is executed after the application is initialized.

 

Use this event to override any global ASPRunner.NET variables. See the description area in the Event editor for the list of available global variables.

 

Note: It is not recommended to use this event to display anything on the web page. Doing so may break your application.

Syntax

public XVar AfterAppInit()

Applies to pages

All pages.

Example

Let's say you need to troubleshoot your application by displaying an executed SQL query at the top of the page.

 

One way to do so is to proceed to the include/appsettings.cs file and set the dDebug variable to true. Though it might be tedious to change this variable back and forth.

 

By using the AfterAppInit event, you can display the debug info by adding debug=true to the URL.

AfterAppInit code:

if (MVCFunctions.postvalue("debug") == "true")
  GlobalVars.dDebug = true;

 

Sample URL: categories/list?debug=true.

 

Note: the Database connection is not yet open in this event. If you need to perform any database operations, open the database connection manually.

using (OdbcConnection connection = new OdbcConnection(strConnection))
  {
    OdbcCommand command = new OdbcCommand("INSERT INTO Log (LastAccesTime) Values(now())");
              command.Connection = connection;
              connection.Open();
              command.ExecuteNonQuery();
  }

Note: in this event, you can also apply the Database API methods to interact with the database.  

Recommended predefined actions and sample events:

Send a simple email

Display a message on the Web page

Redirect to another page

Restrict access to ASPRunner.NET application by IP address

See also:

Query Designer tab

SQLQuery screen

About SQLQuery API

Troubleshooting tips