Skip to content

Filters

Perry edited this page Sep 5, 2018 · 2 revisions

We have built in 2 filters that we found useful. Please read this if you are new to filters. Filters in ASP.NET Core

  1. NeedCode
  2. MustBeLive

NeedCode

If you put this on a controller method, when that method is called the first time the user is redirected to a page and given a code. The user has 5 minutes to enter the provided code and then the original controller method is called again. This provides a barrier between click happy users. For example if you had an admin control panel that allowed you to affect the system and just clicking a button performs the action immediately, it is possible to accidentally initiate this.

Example

[HttpGet("api/test/needcode")]
[NeedCodeFilter]
public IActionResult NeedCodeTest()
{
_logger.LogInformation("api/test/needcode success");
return Ok(new { Message = "Success" });
}

MustBeLive

With the attribute MustBeLive performs a check everytime to see if the system is in the "IsLive" mode. For example; the sending of SMS messages to patients can be circumvented when the system is not live.

Example

[HttpGet("api/test/mustbelive")]
[MustBeLiveFilter]
public IActionResult MustBeLiveTest()
{
_logger.LogInformation("api/test/mustbelive success");
return Ok(new { Message = "Success" });
}

Clone this wiki locally