· 7 years ago · Oct 10, 2018, 06:56 AM
1[HttpPost]
2 public ActionResult FormSubmit()
3 {
4
5 var response = Request["g-recaptcha-response"];
6 string secretKey = "6Lf_NnQUAAA......"; //Added my secret key that genereted on my re-captcha
7 var client = new WebClient();
8 var result = client.DownloadString(string.Format("https://google.com/recaptcha/api/siteverify?secret={0}&response{1}", secretKey, response));
9 var obj = JObject.Parse(result);
10 var status = (bool)obj.SelectToken("success");
11 ViewBag.Message = status ? "successs" : "failed";
12
13 return View();
14 }
15
16<div>
17 @using (Html.BeginForm("FormSubmit", "Home", FormMethod.Post))
18 {
19 <div class="g-recaptcha" data-sitekey="6Lf_NnQUAAA..."></div> //ADDED MY SITE KEY
20 <input type="submit" name="commit" value="Join IoT Lab!">
21 }
22</div>
23<span style="display:inline-block; font-size:20px;margin:20px 0;padding:20px;border:1px solid #D3D3D3">
24 @ViewBag.Message
25</span>
26<p>
27 By clicking "Join IoT Lab", you agree to our <br />
28 <a href="@Url.Action("PrivacyRulesAndGuidelines", "IOTLabProject")">Terms and conditions</a> and <a href="@Url.Action("PrivacyRulesAndGuidelines", "IOTLabProject")">Privacy policy</a>
29</p>
30
31<script src='https://www.google.com/recaptcha/api.js' type="text/javascript"></script>
32
33<div>
34@using (Html.BeginForm("FormSubmit", "Home", FormMethod.Post))
35{
36 <div class="g-recaptcha" data-sitekey="6Lf_NnQUAAA..."></div> //ADDED MY SITE KEY
37 <input type="submit" name="commit" value="Join IoT Lab!">
38}
39</div>
40<span style="display:inline-block; font-size:20px;margin:20px
410;padding:20px;border:1px solid #D3D3D3">
42@ViewBag.Message
43</span>
44<p>
45@if(ViewBag.Message=="successs")
46{
47 By clicking "Join IoT Lab", you agree to our <br />
48 <a href="@Url.Action("PrivacyRulesAndGuidelines", "IOTLabProject")">Terms and
49 conditions</a> and <a href="@Url.Action("PrivacyRulesAndGuidelines",
50 "IOTLabProject")">Privacy policy</a>
51}
52
53 </p>
54
55<script src='https://www.google.com/recaptcha/api.js' type="text/javascript">
56</script>