private void ReadConfig(HttpContext context) { if (SecretKey.IsNotNullOrEmpty()) { return; } if (context.RequestServices.GetService(typeof(IConfiguration)) is not IConfiguration configuration) { throw new ConfigurationException("IConfiguration Service not found."); } var captchaSection = configuration.GetSection("Recaptcha"); if (captchaSection == null) { throw new ConfigurationException( "Recaptcha section not found. The Recaptcha should contain: SiteKey and SecretKey"); } SecretKey = captchaSection["SecretKey"]; if (SecretKey.IsNullOrEmpty()) { throw new ConfigurationException("Recaptcha SecretKey can not bu null or empty."); } }