private TagBuilder getCaptchaImageTagBuilder(string encryptedText) { ViewContext.CheckArgumentNull(nameof(ViewContext)); var values = new CaptchaImageParams { Text = encryptedText, RndDate = DateTime.Now.Ticks.ToString(), ForeColor = ForeColor, BackColor = BackColor, FontSize = FontSize, FontName = FontName }; var serializedValues = _serializationProvider.Serialize(values); var encryptSerializedValues = _captchaProtectionProvider.Encrypt(serializedValues); var actionUrl = _urlHelper.Action( action: nameof(DNTCaptchaImageController.Show), controller: nameof(DNTCaptchaImageController).Replace("Controller", string.Empty), values: new { data = encryptSerializedValues, area = "" }, protocol: ViewContext.HttpContext.Request.Scheme); var captchaImage = new TagBuilder("img"); var dntCaptchaImg = "dntCaptchaImg"; captchaImage.TagRenderMode = TagRenderMode.SelfClosing; captchaImage.Attributes.Add("id", dntCaptchaImg); captchaImage.Attributes.Add("name", dntCaptchaImg); captchaImage.Attributes.Add("alt", "captcha"); captchaImage.Attributes.Add("src", actionUrl); captchaImage.Attributes.Add("style", "margin-bottom: 4px;"); return(captchaImage); }
private string getCaptchaImageUrl(DNTCaptchaTagHelperHtmlAttributes captchaAttributes, string encryptedText) { var values = new CaptchaImageParams { Text = encryptedText, RndDate = DateTime.Now.Ticks.ToString(), ForeColor = captchaAttributes.ForeColor, BackColor = captchaAttributes.BackColor, FontSize = captchaAttributes.FontSize, FontName = captchaAttributes.FontName }; var encryptSerializedValues = _captchaProtectionProvider.Encrypt(_serializationProvider.Serialize(values)); var actionUrl = captchaAttributes.UseRelativeUrls ? _urlHelper.Action(action: nameof(DNTCaptchaImageController.Show), controller: nameof(DNTCaptchaImageController).Replace("Controller", string.Empty), values: new { data = encryptSerializedValues, area = "" }) : _urlHelper.Action(action: nameof(DNTCaptchaImageController.Show), controller: nameof(DNTCaptchaImageController).Replace("Controller", string.Empty), values: new { data = encryptSerializedValues, area = "" }, protocol: _httpContextAccessor.HttpContext.Request.Scheme); if (string.IsNullOrWhiteSpace(actionUrl)) { throw new NullReferenceException("It's not possible to determine the URL of the `DNTCaptchaImageController.Show` method. Please register the `services.AddControllers()` and `endpoints.MapControllerRoute(...)`."); } return(actionUrl); }
private TagBuilder getCaptchaImageTagBuilder(ViewContext viewContext, string encryptedText) { if (_urlHelper == null) { throw new InvalidOperationException("Failed to find the IUrlHelper of ViewContext.HttpContext."); } var values = new CaptchaImageParams { Text = encryptedText, RndDate = DateTime.Now.Ticks.ToString(CultureInfo.InvariantCulture), ForeColor = ForeColor, BackColor = BackColor, FontSize = FontSize, FontName = FontName }; var serializedValues = _serializationProvider.Serialize(values); var encryptSerializedValues = _captchaProtectionProvider.Encrypt(serializedValues); var actionUrl = UseRelativeUrls ? _urlHelper.Action( action: nameof(DNTCaptchaImageController.Show), controller: nameof(DNTCaptchaImageController).Replace("Controller", string.Empty, StringComparison.Ordinal), values: new { data = encryptSerializedValues, area = "" }) : _urlHelper.Action( action: nameof(DNTCaptchaImageController.Show), controller: nameof(DNTCaptchaImageController).Replace("Controller", string.Empty, StringComparison.Ordinal), values: new { data = encryptSerializedValues, area = "" }, protocol: viewContext.HttpContext.Request.Scheme); if (string.IsNullOrWhiteSpace(actionUrl)) { throw new InvalidOperationException("It's not possible to determine the URL of the `DNTCaptchaImageController.Show` method. Please register the `services.AddControllers()` and `endpoints.MapControllerRoute(...)`."); } var captchaImage = new TagBuilder("img"); var dntCaptchaImg = $"{_captchaOptions.CaptchaClass}Img"; captchaImage.TagRenderMode = TagRenderMode.SelfClosing; captchaImage.Attributes.Add("id", dntCaptchaImg); captchaImage.Attributes.Add("name", dntCaptchaImg); captchaImage.Attributes.Add("alt", "captcha"); captchaImage.Attributes.Add("src", actionUrl); captchaImage.Attributes.Add("style", "margin-bottom: 4px;"); return(captchaImage); }
private TagBuilder getCaptchaImageTagBuilder(string encryptedText) { ViewContext.CheckArgumentNull(nameof(ViewContext)); var values = new CaptchaImageParams { Text = encryptedText, RndDate = DateTime.Now.Ticks.ToString(), ForeColor = ForeColor, BackColor = BackColor, FontSize = FontSize, FontName = FontName, UseNoise = UseNoise }; var serializedValues = _serializationProvider.Serialize(values); var encryptSerializedValues = _captchaProtectionProvider.Encrypt(serializedValues); var actionUrl = UseRelativeUrls ? _urlHelper.Action( action: nameof(DNTCaptchaImageController.Show), controller: nameof(DNTCaptchaImageController).Replace("Controller", string.Empty), values: new { data = encryptSerializedValues, area = "" }) : _urlHelper.Action( action: nameof(DNTCaptchaImageController.Show), controller: nameof(DNTCaptchaImageController).Replace("Controller", string.Empty), values: new { data = encryptSerializedValues, area = "" }, protocol: ViewContext.HttpContext.Request.Scheme); if (string.IsNullOrWhiteSpace(actionUrl)) { throw new NullReferenceException("It's not possible to determine the URL of the `DNTCaptchaImageController.Show` method. Please register the `services.AddControllers()` and `endpoints.MapControllerRoute(...)`."); } var captchaImage = new TagBuilder("img"); var dntCaptchaImg = "dntCaptchaImg"; captchaImage.TagRenderMode = TagRenderMode.SelfClosing; captchaImage.Attributes.Add("id", dntCaptchaImg); captchaImage.Attributes.Add("name", dntCaptchaImg); captchaImage.Attributes.Add("alt", "captcha"); captchaImage.Attributes.Add("src", actionUrl); captchaImage.Attributes.Add("style", "margin-bottom: 4px;"); return(captchaImage); }
private string getCaptchaImageUrl(DNTCaptchaTagHelperHtmlAttributes captchaAttributes, string encryptedText) { var values = new CaptchaImageParams { Text = encryptedText, RndDate = DateTime.Now.Ticks.ToString(), ForeColor = captchaAttributes.ForeColor, BackColor = captchaAttributes.BackColor, FontSize = captchaAttributes.FontSize, FontName = captchaAttributes.FontName }; var encryptSerializedValues = _captchaProtectionProvider.Encrypt(_serializationProvider.Serialize(values)); var actionUrl = Url.Action(action: nameof(DNTCaptchaImageController.Show), controller: nameof(DNTCaptchaImageController).Replace("Controller", string.Empty), values: new { data = encryptSerializedValues, area = "" }, protocol: HttpContext.Request.Scheme); return(actionUrl); }