How do I determine which Website environment is running?

I'm currently trying to provide some helpful information for a Website endpoint to assist developers when they call with a bad request. A security audit flagged this as a potential issue due to exposing information. I have decided that it might still be worthwhile in lower environments, so I would like to do a conditional check for CI and Demo (and maybe local). How can I determine this within a Website controller? I will not have a session yet as this is a standalone endpoint using microsession.

Best Answer

  • You don't ever want to do an environment check in Cobalt. Instead, use a value from CMDB which can be used to enable/disable certain functionality based on environment. The value you want to use is a CMDB property called `ShowStackTrace`. This is enabled in lower environments and disabled in higher environments. You can get the value of this property by injecting the `IProductApplicationSettings` interface.

Answers

  • I'm pretty sure you can use the ProductSettings.Environment property that is available in Cobalt Website without a session.
  • It should be ok to use this property for display purposes, but as Andrew mentions, it should never be used for conditional code logic!
  • Ok, so better than environment?
  • Yeah you will be overloading the purpose of `ShowStackTrace`, as it was originally only meant to determine whether we should show the stack trace on the page in error scenarios, but its in the same spirit (displaying logging information). Maybe the CMDB property needs to be changed to be a little more generic?