Cách nhúng reCaptcha vào ASP.NET website

Cách nhúng reCaptcha vào ASP.NET website

reCaptcha là 1 dịch vụ giúp chúng ta có thể chống lại bot, và những submit không phải do con người (do engine). Bài viết này sẻ hướng dẫn cách nhúng reCaptcha vào ASP.NET sử dụng cả C# và VB.NET. 

Cách nhúng reCaptcha vào ASP.NET website

Các bước thực hiện: 

1. Bạn vào địa chỉ http://www.google.com/recaptcha và nhấn vào nút MY ACCOUNT

2. Sau đó bạn sẽ được chuyển sang trang yêu cầu đăng nhập bằng tài khoản google của bạn. (Yêu cầu bạn cần có tài khoản google để đăng ký sử dụng). Sau khi bạn đăng nhập thành công, bạn sẽ được chuyển sang trang tạo key cho reCatcha.

Bạn điền tên miền của website bạn muốn tạo recaptcha  vào ô Domain. Sau đó check chọn "Enable this key on all domains (global key)" và nhấn Create Key. Hoàn tất bước trên bạn sẽ có được public key và Private key.

3. Download thư viện reCaptcha

Phiên bản mới nhất có thể được download từ google code.

4. Tạo 1 ứng dụng ASP.NET C# or VB.NET.

5. Add Recaptcha.dll vào toolbox và kéo thả vào WebForm, tiếp theo dán 2 giá trị private và public key.

6. Kéo button và code cho sự kiện click, 1 label y thông báo thành công hoặc là không.

Source code C#:

protected void ButtonSubmit_Click(object sender, EventArgs e)

{

if (Page.IsValid)

{

LabelResult.Visible = true;

LabelResult.ForeColor = System.Drawing.Color.Green;

LabelResult.Text = "Captcha match!";

}

else

{

LabelResult.Visible = true;

LabelResult.ForeColor = System.Drawing.Color.Red;

LabelResult.Text = "Captcha invalid.";

}

}

Source code VB.NET

Protected Sub ButtonSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs)

Handles ButtonSubmit.Click

If Page.IsValid Then

LabelResult.Visible = True

LabelResult.ForeColor = Drawing.Color.Green

LabelResult.Text = "Captcha match!"

Else

LabelResult.Visible = True

LabelResult.ForeColor = Drawing.Color.Red

LabelResult.Text = "Captcha invalid."

End If

End Sub

Và đây là kết quả, khi nhập đúng giá trị captcha

Và đây là kết quả, khi nhập sai giá trị captcha

Bạn thấy bài viết này như thế nào?: 
Average: 8 (1 vote)
Ảnh của Tommy Tran

Tommy owner Express Magazine

Drupal Developer having 9+ year experience, implementation and having strong knowledge of technical specifications, workflow development. Ability to perform effectively and efficiently in team and individually. Always enthusiastic and interseted to study new technologies

  • Skype ID: tthanhthuy

Advertisement

 

jobsora

Dich vu khu trung tphcm

Dich vu diet chuot tphcm

Dich vu diet con trung

Quảng Cáo Bài Viết

 
Navigating Entity URIs trong Drupal 7

Thực hành ví dụ với khái niệm: Navigating Entity URIs trong Drupal 7

Did you notice the little restriction I worked into my first two examples there? MailChimp and Registration are only for “fieldable entities”.

 Facebook Chat is one of the easiest way to chat with your friends and share your thoughts with your friends and family.

Add Images on Your Facebook Chat With Smileytime

Facebook Chat is one of the easiest way to chat with your friends and share your thoughts with your friends and family. 

Nofollow là gì? Cách xây dựng Backlinks

Một trong những kỹ thuật SEO, để gia tăng thứ hạng cho website đó là “Xây dựng Backlinks” nếu site của bạn được những site có thứ hạng cao liên kết tới, bạn sẽ được Search Engines tìm đến nhanh hơn.

Công ty diệt chuột T&C

 

Diet con trung