1

Is there a more convenient way to make the action available only to X environment ?

For the time being, I can do something simple as this :

    [HttpGet]
    public IActionResult MenualTransactionHandling()
    {
        if(env.IsDevelopment())
        {
            // Code
            return Ok();
        }
        else
        {
            // Any other enviroment will not enter
            return Forbid();
        }
    }

I would like something like this :

[Development]
public IActionResult MenualTransactionHandling() { /*Code*/ return Ok(); }
OZ_CM
  • 41
  • 4
  • See https://stackoverflow.com/a/41579022/11683 and links there there for how to define an authorization attribute based on the environment. – GSerg Sep 23 '19 at 07:05
  • If its purely a debug action and doesn't need to be in any other builds, you could use also wrap it in a [#if block](https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/preprocessor-directives/preprocessor-if) or mark it with a [conditionalattribute](https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.conditionalattribute). This would remove it entirely unless some compiler symbols are defined. – RMH Sep 23 '19 at 07:43
  • Thanks, both of you helped me alot! Since it was for debugging purposes, I made a simple action filter with the #if DEBUG block for checking – OZ_CM Sep 23 '19 at 09:52

0 Answers0