Startup
The most common Wisej applications (in the broad sense) have only a single application (in the strict sense). To keep things simple, we will use sub-application to refer to an application in the strict sense.
Wisej sub-applications are different entry points in your application, which are independent URL you can use for whatever purpose you decide. All Wisej projects must have at least one sub-application that is created by default.

Startup Files

When you create a new Wisej project, Wisej creates 3 startup files:
  • Default.html
  • Default.json
  • Program.cs
Default.html is used because that’s the filename we are used to, for a startup page in ASP.NET.
Program.cs is used because that’s where we look for the static (Shared in VB) Main method.
For simplicity, the .html and .json filenames should match, but they don't have to match.
You can rename Default.html and Default.json to anything. You can also use an .aspx file in case you need to run .NET code before the Wisej application is loaded, see Wisej.UserData for an example.

Sub-Applications

Creating

You can create a sub-application in the project's root or in a project's folder.
To create a sub-application, follow the steps:
  1. 1.
    Right click on the project (or a project's folder), selecting Add -> New Item.
  2. 2.
    On the Add New Item form, select Wisej on the left side and click on Application in the list.
  3. 3.
    Set the application Name and click Add.
Supposing you set the Name to Admin, Wisej creates 3 startup files, all with the same name:
  • Admin.html
  • Admin.json
  • Admin.cs
The Admin.cs file is just like the Program.cs default file and looks like this:
C#
VB.NET
1
static class Admin
2
{
3
/// <summary>
4
/// The main entry point for the application.
5
/// </summary>
6
static void Main()
7
{
8
}
9
}
Copied!
1
Public Module Program
2
3
''' <summary>
4
''' The main entry point for the application.
5
''' </summary>
6
Public Sub Main()
7
End Sub
8
9
End Moule
Copied!

Running

We are trained to look for the .html file as the starting point for a web application. In fact, the Wisej sub-application starts by the .json file. Even when we type an URL that includes the .html part, Wisej looks for is the .json file. Later on, we will discuss the rules Wisej uses to get a .json file.
In the Admin sub-application we created, the Admin.json file looks like this:
JSON
1
{
2
"url": "Admin.html",
3
"startup": "[ProjectName].Admin.Main, [ProjectName]"
4
}
Copied!
This file tells Wisej two important pieces of information:
  • What .html file to show on the browser - the "url" key.
  • What startup method to run on the server - the "startup" key.
When the user types http://myApp.com/Admin, Wisej will find Admin.json, read the "url" key and load Admin.html and then invoke the startup method in Admin.json.
Browsers need an HTML-like file and Wisej needs the browser to load and execute wisej.wx. More on this later.
Instead of the startup method, we can specify the sub-application's main view. More on this below.

Entry Point

Wisej needs to know what method the server should execute on startup, in this case the method [ProjectName].Project.Main on assembly [ProjectName].
Say that instead of executing the Main method, we want to instantiate an AdminPage. In fact, most of the time, all the Main method does is instantiate a view (Form or Page). In this case, the Default.json file should look like:
JSON
1
{
2
"url": "Default.html",
3
"mainWindow": "[ProjectName].AdminPage, [ProjectName]"
4
}
Copied!

Startup Workflow

Putting it all together, you will find the Wisej startup workflow quite simple. It's composed of the following steps:
  1. 1.
    Find a .json file.
  2. 2.
    Tell the browser to load and show the "url" HTML file.
  3. 3.
    Tell the server what to do, according to the key specified in the .json file:
    • Execute the "startup" method or
    • Instantiate (invoke the constructor of) the "mainWindow" view.
If you specify both, the "startup" and "mainWindow" properties, Wisej will execute both.

Rules for finding the .json file

  1. 1.
    Replace the extension by .json If you type an URL that ends with an extension (html or any other extension), like http://myserver.com/Startup.php, if the file exists, Wisej tries to find the matching .json file (a file with the same name, but with the json extension instead of supplied extension). In this case it looks for \Startup.json. If Wisej is already loaded and cannot find a matching json file, the wisej.wx script reloads the same page.
  2. 2.
    Append Default.json to a folder path If you type an URL that refers to a folder, be it the root folder http://myserver.com or an URL that ends with "/" like http://myserver.com/Suppliers/, Wisej uses Default.json file at the specified folder location. In these cases, respectively at \Default.json and at \Suppliers\Default.json.
  3. 3.
    Append either .json extension or \Default.json If you type an URL that does NOT end with any extension like http://myserver.com/Customers, Wisej tries to find the .json file in two steps:
    • Wisej appends .json to Customers and looks for \Customers.json.
    • If \Customers.json doesn't exist, Wisej presumes Customers is a folder and appends \Default.json to the folder path. In this case, it looks for the .json file at \Customers\Default.json.

No need for a default document

The Web.config file created by Wisej project templates, by default includes a section like this:
1
<defaultDocument enabled="true">
2
<files>
3
<add value="Default.html" />
4
</files>
5
</defaultDocument>
Copied!
According to rule 2) above, you don't need defaultDocument to be defined in the Web.config file.
If the URL is the web site URL, it refers to a folder and Wisej looks for the .json file at the project's root folder, it looks for \Default.json.
Last modified 1mo ago