コード例 #1
0
        public async Task <FileContentResult> CaptchaAsync([FromServices] ICaptchaService _captchaServices)
        {
            //if (_captchaServices == null) throw new ArgumentNullException(nameof(_captchaServices), "ICaptchaServices未注入,请在CaptchaServices的属性ServiceLifetimeAttribute中启用");
            var code = await _captchaServices.GenerateRandomCaptchaAsync();

            var result = await _captchaServices.GenerateCaptchaImageAsync(code);

            return(File(result.CaptchaMemoryStream.ToArray(), "image/png"));
        }