﻿
{"id":1965,"date":"2013-08-14T21:45:28","date_gmt":"2013-08-14T21:45:28","guid":{"rendered":"http:\/\/www.gencayyildiz.com\/blog\/?p=1965"},"modified":"2013-08-26T22:13:12","modified_gmt":"2013-08-26T22:13:12","slug":"asp-net-mvc-4-0-recaptcha-nesnesi","status":"publish","type":"post","link":"https:\/\/www.gencayyildiz.com\/blog\/asp-net-mvc-4-0-recaptcha-nesnesi\/","title":{"rendered":"Asp.NET MVC 4.0 &#8211; ReCaptcha Nesnesi"},"content":{"rendered":"<div id=\"fb-root\"><\/div>\n<p>Web site sahiplerinin midesini bulunduran spam sald\u0131r\u0131lar\u0131 ve sisteminizi yormak i\u00e7in hackerlar taraf\u0131ndan geli\u015ftirilmi\u015f i\u00e7erik g\u00f6nderme yaz\u0131l\u0131mlar\u0131na \u00f6nlem ama\u00e7l\u0131 <em>Recaptcha<\/em> testi geli\u015ftirilmi\u015ftir.Bu test olduk\u00e7a kullan\u0131\u015fl\u0131 oldu\u011fundan dolay\u0131 daha sonra Google taraf\u0131ndan sat\u0131n al\u0131nm\u0131\u015ft\u0131r.Sitenize gelen ziyaret\u00e7inin herhangi bir veri kay\u0131t i\u015fleminde bulunmas\u0131 esnas\u0131nda bu test ile insan ya da bot oldu\u011funu ay\u0131rt edebiliyor ve i\u015flemleri ona g\u00f6re tabi tutabiliyorsunuz.E\u011fer ziyaret\u00e7i <em>Recaptcha<\/em> testini ge\u00e7emezse yap\u0131lacak i\u015flem tetiklenmiyor ve ziyaret\u00e7iye uyar\u0131 veriliyor.Asp.NET MVC 4.0 mimarisi, olu\u015fturdu\u011fumuz sistemlerimizde Recaptcha nesnesini rahatl\u0131kla kullanabilme olana\u011f\u0131n\u0131 tan\u0131yor.<br \/>\n<!--more--><br \/>\n\u00d6ncelikle bu nesneyi projenizde kullanabilmeniz i\u00e7in Microsoft Web Helpers Paketini referans olarak eklemeniz gerekmektedir.Bu i\u015flemi <a href=\"http:\/\/www.gencayyildiz.com\/blog\/asp-net-mvc-microsoft-web-helpers-paketi-yuklenmesi\/\" target=\"_blank\">Asp.NET MVC &#8211; Microsoft Web Helpers Paketi Y\u00fcklenmesi<\/a> ba\u015fl\u0131kl\u0131 yaz\u0131mda nas\u0131l yapabilece\u011finize \u00f6nceden de\u011finmi\u015ftim.<\/p>\n<p>Recaptcha nesnesini programatik olarak kullanabilmeniz i\u00e7in Google taraf\u0131ndan kay\u0131tl\u0131 bir domaininiz olmas\u0131 gerekmektedir.Bu i\u015flem i\u00e7in \u00f6ncelikle <a href=\"http:\/\/www.google.com\/recaptcha\" target=\"_blank\">http:\/\/www.google.com\/recaptcha<\/a> adresine giderek &#8220;Use Recaptcha On Your Site&#8221; yazan butona t\u0131klayarak kay\u0131t olmam\u0131z gerekmektedir.<\/p>\n<p><a href=\"http:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2013\/08\/Recaptcha.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2013\/08\/Recaptcha-300x239.png\" alt=\"Recaptcha\" width=\"300\" height=\"239\" class=\"aligncenter size-medium wp-image-1969\" srcset=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2013\/08\/Recaptcha-300x239.png 300w, https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2013\/08\/Recaptcha.png 599w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Yukar\u0131daki resimde g\u00f6rd\u00fc\u011f\u00fcn\u00fcz gibi domain adresinizi yazd\u0131ktan sonra &#8220;Create Key&#8221; butonuna t\u0131klay\u0131n\u0131z.E\u011fer ki, alt domainlerde Recaptcha kullan\u0131lacaksa &#8220;Enable this key on all domains (global key)&#8221; yazan kutucu\u011fu t\u0131klaman\u0131z yeterlidir.<\/p>\n<p><a href=\"http:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2013\/08\/Recaptcha2.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2013\/08\/Recaptcha2.png\" alt=\"Recaptcha2\" width=\"191\" height=\"247\" class=\"aligncenter size-full wp-image-1971\" \/><\/a><\/p>\n<p>Bu i\u015flemler neticesinde yukar\u0131da g\u00f6rd\u00fc\u011f\u00fcn\u00fcz gibi bir sayfa gelecektir.Bu sayfadan <em>Public Key<\/em> ve <em>Private Key<\/em> kodlar\u0131n\u0131 alm\u0131\u015f olaca\u011f\u0131z.Art\u0131k kodlamam\u0131za ge\u00e7ebiliriz.<\/p>\n<p>\u015eimdi MVC projemizde &#8220;Home(Controller).cs&#8221; ad\u0131nda bir Controller s\u0131n\u0131f\u0131 a\u00e7al\u0131m.Bu s\u0131n\u0131f i\u00e7erisinde ActionResult tipinden &#8220;Index&#8221; isimli metodumuzun View katman\u0131ndaki &#8220;.cshtml&#8221; uzant\u0131l\u0131 sayfas\u0131n\u0131 olu\u015ftural\u0131m.<\/p>\n<p>Mant\u0131k \u015fu;<br \/>\nRecaptcha testinini kontrol etmek ama\u00e7l\u0131 bir Action metod olu\u015fturaca\u011f\u0131z ve Index.cshtml sayfam\u0131zda bu Action metodumuz \u00fczerinden i\u015flem yapaca\u011f\u0131z.<\/p>\n<p>Ben &#8220;TestKontrol&#8221; isimli bir Action metod olu\u015fturup i\u00e7ini a\u015fa\u011f\u0131daki gibi kodluyorum.<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n        public ActionResult Index(int? id)\r\n        {\r\n            if (id != null)\r\n            {\r\n                if (id == 1)\r\n                {\r\n                    ViewData&#x5B;&quot;Durum&quot;] = &quot;Do\u011fru&quot;;\r\n                }\r\n                else\r\n                {\r\n                    ViewData&#x5B;&quot;Durum&quot;] = &quot;Yanl\u0131\u015f&quot;;\r\n                }\r\n            }\r\n            return View();\r\n        }\r\n\r\n        public ActionResult TestKontrol()\r\n        {\r\n            if (ReCaptcha.Validate(privateKey: &quot;6LerHe***&quot;))\r\n            {\r\n                return RedirectToAction(&quot;Index&quot;, new { id = 1 });\r\n            }\r\n            return RedirectToAction(&quot;Index&quot;, new { id = 2 });\r\n        }\r\n<\/pre>\n<p>Bu metodumuz tetiklendi\u011fi anda Recaptcha testimizin Private Key kodunu alarak denetleme yap\u0131yor ve e\u011fer sonu\u00e7 do\u011fru ise Index Action metodumuza giderek id isimli Route&#8217;a 1 de\u011ferini, de\u011fil ise 2 de\u011ferini g\u00f6nderiyor.Index Action metodumuzda g\u00f6rd\u00fc\u011f\u00fcn\u00fcz gibi id parametresini yakalay\u0131p gerekli kontrol i\u015flemlerini ger\u00e7ekle\u015ftiriyoruz ve ona g\u00f6re ViewData nesnemizde &#8220;Durum&#8221; isimli de\u011fi\u015fken olu\u015fturup geriye g\u00f6nderece\u011fimiz de\u011feri yaz\u0131yoruz.<\/p>\n<p>\u015eimdi testimizi &#8220;Index.cshtml&#8221; sayfas\u0131nda g\u00f6rsel olarak uygulamaya ge\u00e7elim.<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n@using Microsoft.Web.Helpers\r\n@using (Html.BeginForm(&quot;TestKontrol&quot;, &quot;Home&quot;, FormMethod.Post))\r\n{\r\n    @ReCaptcha.GetHtml(publicKey: &quot;6LerHe***&quot;);\r\n    &lt;input type=&quot;submit&quot; value=&quot;Kontrol Et&quot; \/&gt;\r\n    if (ViewData&#x5B;&quot;Durum&quot;] != null)\r\n    {\r\n        @ViewData&#x5B;&quot;Durum&quot;]\r\n    }\r\n}\r\n<\/pre>\n<p>Burada ise &#8220;Kontrol Et&#8221; isimli buton tetiklendi\u011fi anda &#8220;Home(Controller).cs&#8221; isimli Controller s\u0131n\u0131f\u0131m\u0131zdaki &#8220;TestKontrol&#8221; isimli Action metodumuza Recaptcha bilgileri Post ediliyor ve denetleniyor.Recaptcha nesnemizin GetHtml metodu ile Public Key kodu girilerek Client bazl\u0131 g\u00f6rsel i\u015flem ve kontrol ba\u011flant\u0131s\u0131 kuruluyor.Gelecek olan sonu\u00e7 ViewData nesnemizle istenilen alana yazd\u0131r\u0131l\u0131yor.<\/p>\n<p>Sonu\u00e7 olarak projemizi derleyip \u00e7al\u0131\u015ft\u0131rd\u0131\u011f\u0131m\u0131zda a\u015fa\u011f\u0131daki g\u00f6r\u00fcnt\u00fc ekrana gelecektir.Olu\u015fturulan karakterleri do\u011fru ya da yanl\u0131\u015f yazman\u0131z neticesinde gerekli sonu\u00e7 ekranda g\u00f6z\u00fckecektir.<br \/>\n<a href=\"http:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2013\/08\/Recaptcha3.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2013\/08\/Recaptcha3-300x147.png\" alt=\"Recaptcha3\" width=\"300\" height=\"147\" class=\"aligncenter size-medium wp-image-1973\" srcset=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2013\/08\/Recaptcha3-300x147.png 300w, https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2013\/08\/Recaptcha3.png 312w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Bu yaz\u0131m\u0131z\u0131nda sonuna gelmi\u015f bulunmaktay\u0131z.<br \/>\nFaydalanman\u0131z dile\u011fiyle..<br \/>\nSonraki yaz\u0131lar\u0131mda g\u00f6r\u00fc\u015fmek \u00fczere..<br \/>\n\u0130yi \u00e7al\u0131\u015fmalar..<\/p>\n<!-- AddThis Advanced Settings generic via filter on the_content --><!-- AddThis Share Buttons generic via filter on the_content -->","protected":false},"excerpt":{"rendered":"<p>Web site sahiplerinin midesini bulunduran spam sald\u0131r\u0131lar\u0131 ve sisteminizi yormak i\u00e7in hackerlar taraf\u0131ndan geli\u015ftirilmi\u015f i\u00e7erik g\u00f6nderme yaz\u0131l\u0131mlar\u0131na \u00f6nlem ama\u00e7l\u0131 Recaptcha testi geli\u015ftirilmi\u015ftir.Bu test olduk\u00e7a kullan\u0131\u015fl\u0131 oldu\u011fundan dolay\u0131 daha sonra Google taraf\u0131ndan sat\u0131n al\u0131nm\u0131\u015ft\u0131r.Sitenize gelen&#46;&#46;&#46;<!-- AddThis Advanced Settings generic via filter on get_the_excerpt --><!-- AddThis Share Buttons generic via filter on get_the_excerpt --><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11,345],"tags":[746,253,755,421],"class_list":["post-1965","post","type-post","status-publish","format-standard","hentry","category-asp-net-mvc","category-mvc-4-0","tag-asp-net-mvc","tag-google","tag-mvc-4-0","tag-recaptcha"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/posts\/1965","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/comments?post=1965"}],"version-history":[{"count":0,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/posts\/1965\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/media?parent=1965"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/categories?post=1965"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/tags?post=1965"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}