0

Hi I am trying to implement the captcha of botdetect in MVC Core 6. After a lots of search i don't find any solution for MVC Core 6. If Anyone have an idea for using on mvc 6.0 than tell me.

steps completed on my side are:

  1. Installation of Captcha completed.

  2. created a captchahelper class for for design implementation here is the code:

    using System; using System.Collections.Generic; using System.Linq; using System.Web; using BotDetect.Web.Mvc;

     namespace ePost.Common
     {
         public static class CaptchaHelper
         {
             public static MvcCaptcha GetRegistrationCaptcha()
             {
                 // create the control instance
                 MvcCaptcha registrationCaptcha = new MvcCaptcha("RegistrationCaptcha");
                 // set up client-side processing of the Captcha code input textbox
                 registrationCaptcha.UserInputID = "CaptchaCode";
                 registrationCaptcha.HelpLinkEnabled = false;
                 registrationCaptcha.HelpLinkText = "";
                 registrationCaptcha.HelpLinkUrl = "#";
                 // Captcha settings
                 registrationCaptcha.ImageSize = new System.Drawing.Size(200, 50);
                 registrationCaptcha.CodeLength = 4;
    
                 return registrationCaptcha;
             }
             public static MvcCaptcha GetLoginCaptcha()
             {
                 // create the control instance
                 MvcCaptcha loginCaptcha = new MvcCaptcha("LoginCaptcha");
    
                 // set up client-side processing of the Captcha code input textbox
                 loginCaptcha.UserInputID = "CaptchaCode";
                 loginCaptcha.HelpLinkEnabled = false;
                 loginCaptcha.HelpLinkText = "";
                 loginCaptcha.HelpLinkUrl = "#";
                 // Captcha settings
                 loginCaptcha.ImageSize = new System.Drawing.Size(200, 50);
                 loginCaptcha.CodeLength = 4;
    
                 return loginCaptcha;
    
             }
         }
     }
    
  3. Now i am trying to display this captcha on view with using this code:

    @{ MvcCaptcha loginCaptcha = CaptchaHelper.GetLoginCaptcha(); }
                      @Html.Captcha(loginCaptcha)        
    
                       <div class="form-card">
                           <div class="mt-4" style="margin-bottom:-40px;">
                               <label for="captchareg" class="fieldlabels">Type Above Code:</label>
                               <input asp-for="CaptchaCode" class="form-input captchaVal valid space-not textbox" id="captchareg" maxlength="10" />
                               <span class="b-placeholderreg">Type Above Code</span>
                               <span asp-validation-for="CaptchaCode" class="text-danger"></span>
                           </div>
                       </div>
                   </fieldset>
    
  4. @Html.Captcha(loginCaptcha) this line of code is working on normal MVC but it is not working in MVC core 6. Am i missing something please tell me. is there any need to inject this captcha service in program.cs file than please tell me.

If Anyone have a aolution for this please tell me.

Progman
  • 16,827
  • 6
  • 33
  • 48

1 Answers1

0

Juding from the namespace using BotDetect.Web.Mvc; you referred, you codes were for Asp.Net(Not core), you have to find a solution for .net core

Ruikai Feng
  • 6,823
  • 1
  • 2
  • 11