Controller

How to add a new Controller

  1. Right-click on the "Controllers" folder

  2. Choose "Add" > "Controller..."

  3. Change default inherited class "Controller" into "BaseController"

The Controller Signature should look like this:

public class ExampleController : BaseController

Actions

Every Controller contains a set of "Actions" that enable communication to the Server, i.e. making requests. The standard signature of an Action looks like this:

public ActionResult ActionName (...)

For an Action to be detected, it needs to have 3 Key words that will be described in the following:

Authorization Key Words

There are two Key Words that take care of the authorization of Actions that is required to be able to use them:

  • [Authorize] applies authentication to the Action

  • [AuthorizeRole] applies role authorization to the Action

These two Key Words need to be put on top of the Action Signature for an Action to be authorized for usage. However, since usually all Actions of a Controller should be authorized, it is easier to put the two Key Words on top of the Controller instead of every single Action. When they are put on top of the Controller, the authorization is automatically applied to all Actions created within this Controller. Thus, the Controller Signature would look like this:

[Authorize]
[AuthorizeRole]
public class ExampleController : BaseController

HTTP Methods

Other than Authorization, an Action also requires a so-called "HTTP Method" to be detected for usage. HTTP Methods signalize what type of request an Action is handling. There are 4 types of requests that are distinguished by the interactions with the database that the request requires. Those 4 types are known as "CRUD" (Create-Read-Update-Delete). Each HTTP Method corresponds to one of the 4 types:

[HttpGet]

[HttpGet] is used when you only want to Read data from the Server to be displayed to the Client (i.e. no change is done to the database). So for example, to simply open a webpage, you would use an HTTPGET Action.

The signature of an HTTPGET Action would look like this:

[HttpGet]
public ActionResult ActionName (...)

When used to load the page, it additionally needs to be added in the Navigation first (see Navigation Editor).

[HttpPost]

[HttpPost] is used when you want to Create new data to be stored in the Server. So for example, if you want to add an entry in a webpage, you would use an HTTPPOST Action.

The signature of an HTTPPOST Action would look like this:

[HttpPost]
public ActionResult ActionName (...)

[HttpDelete]

[HttpDelete] is used when you want to Delete data from the Server. So for example, if you want to remove an entry from a webpage, you would use an HTTPDELETE Action.

The signature of an HTTPDELETE Action would look like this:

[HttpDelete]
public ActionResult ActionName (...)

[HttpPut]

[HttpPut] is used when you want to Update existing data from the Server. So for example, if you want to change the value of a property of a particular entry, you would use an HTTPPUT Action.

The signature of an HTTPPUT Action would look like this:

[HttpPut]
public ActionResult ActionName (...)

After adding a new Action, it needs to be registered to be able to use it as described in the article Access Control.

When clicking the "Synch" Button in the Access Controls page, only Actions are detected that have all Key Words applied to them ([Authorize], [AuthorizeRole], [HttpXXX]), i.e. only those can be registered in the Access Controls page.

Grouping Actions

To have a better overview of all the Actions in a Controller, we group them using the syntax below:

#region Group Name
...
#endregion

The above code will create a "-" symbol on the left margin. When clicked, it will minimize all Actions in-between, so that only "Group Name" will be visible, and the "-" symbol turns into a "+" symbol. You can expand the Actions again by clicking "+".

Usually all Actions belonging to the same page are put in one group with the page's name as Group Name.

Last updated