ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2017 www.aspforums.com. All rights reserved.Google RECaptcha with URL routing in ASP.Net<p>Hi&nbsp;<a class="username" rel="counterkin">counterkin,</a></p> <p>Here i have created a sample with url routing.</p> <p><span style="text-decoration: underline;">Global.asax </span></p> <pre class="brush: xml">&lt;script runat=&#34;server&#34;&gt; void Application_Start(object sender, EventArgs e) { RegisterRoutes(RouteTable.Routes); } static void RegisterRoutes(RouteCollection routes) { routes.MapPageRoute(&#34;Customers&#34;, &#34;Customers&#34;, &#34;~/Customers.aspx&#34;); routes.MapPageRoute(&#34;CustomerDetails&#34;, &#34;Customers/{CustomerId}&#34;, &#34;~/CustomerDetails.aspx&#34;); } &lt;/script&gt;</pre> <p><span style="text-decoration: underline;">HTML</span></p> <p><span style="text-decoration: underline;">Default.aspx</span></p> <pre class="brush: html">&lt;h1&gt; Home&lt;/h1&gt; &lt;hr /&gt; &lt;a href=&#39;&lt;%=ResolveUrl(&#34;~/Customers&#34;) %&gt;&#39;&gt;View Customers&lt;/a&gt;&lt;/form&gt;</pre> <p><span style="text-decoration: underline;">Customers.aspx</span></p> <pre class="brush: html">&lt;h1&gt; Customers&lt;/h1&gt; &lt;hr /&gt; &lt;asp:GridView ID=&#34;GridView1&#34; runat=&#34;server&#34; AutoGenerateColumns=&#34;false&#34;&gt; &lt;Columns&gt; &lt;asp:BoundField DataField=&#34;Id&#34; HeaderText=&#34;Id&#34; ItemStyle-Width=&#34;30&#34; /&gt; &lt;asp:BoundField DataField=&#34;Name&#34; HeaderText=&#34;Name&#34; ItemStyle-Width=&#34;150&#34; /&gt; &lt;asp:BoundField DataField=&#34;Country&#34; HeaderText=&#34;Country&#34; ItemStyle-Width=&#34;150&#34; /&gt; &lt;asp:HyperLinkField Text=&#34;View&#34; DataNavigateUrlFormatString=&#34;~/Customers/{0}&#34; DataNavigateUrlFields=&#34;Id&#34; /&gt; &lt;/Columns&gt; &lt;/asp:GridView&gt; &lt;br /&gt; &lt;script type=&#34;text/javascript&#34; src=&#34;http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js&#34;&gt;&lt;/script&gt; &lt;script type=&#34;text/javascript&#34; src=&#34;https://www.google.com/recaptcha/api.js?onload=onloadCallback&amp;render=explicit&#34; async defer&gt;&lt;/script&gt; &lt;script type=&#34;text/javascript&#34;&gt; var onloadCallback = function () { grecaptcha.render(&#39;dvCaptcha&#39;, { &#39;sitekey&#39;: &#39;&lt;%=ReCaptcha_Key %&gt;&#39;, &#39;callback&#39;: function (response) { $.ajax({ type: &#34;POST&#34;, url: &#34;Customers.aspx/VerifyCaptcha&#34;, data: &#34;{response: &#39;&#34; + response + &#34;&#39;}&#34;, contentType: &#34;application/json; charset=utf-8&#34;, dataType: &#34;json&#34;, success: function (r) { var captchaResponse = jQuery.parseJSON(r.d); if (captchaResponse.success) { $(&#34;[id*=txtCaptcha]&#34;).val(captchaResponse.success); $(&#34;[id*=rfvCaptcha]&#34;).hide(); } else { $(&#34;[id*=txtCaptcha]&#34;).val(&#34;&#34;); $(&#34;[id*=rfvCaptcha]&#34;).show(); var error = captchaResponse[&#34;error-codes&#34;][0]; $(&#34;[id*=rfvCaptcha]&#34;).html(&#34;RECaptcha error. &#34; + error); } } }); } }); }; &lt;/script&gt; &lt;div id=&#34;dvCaptcha&#34;&gt; &lt;/div&gt; &lt;asp:Button ID=&#34;btnSubmit&#34; Text=&#34;Submit&#34; runat=&#34;server&#34; /&gt;</pre> <p><span style="text-decoration: underline;">CustomerDetails.aspx</span></p> <pre class="brush: html">&lt;h1&gt; Customer Details&lt;/h1&gt; &lt;hr /&gt; &lt;b&gt;Customer Id:&lt;/b&gt; &lt;asp:Label ID=&#34;lblCustomerId&#34; runat=&#34;server&#34; /&gt;</pre> <p><span style="text-decoration: underline;">Code</span></p> <p><span style="text-decoration: underline;">Customers.aspx.cs</span></p> <pre class="brush: csharp">protected void Page_Load(object sender, EventArgs e) { if (!this.IsPostBack) { DataTable dt = new DataTable(); dt.Columns.AddRange(new DataColumn[3] { new DataColumn(&#34;Id&#34;, typeof(int)), new DataColumn(&#34;Name&#34;), new DataColumn(&#34;Country&#34;) }); dt.Rows.Add(1, &#34;John Hammond&#34;, &#34;United States&#34;); dt.Rows.Add(2, &#34;Mudassar Khan&#34;, &#34;India&#34;); dt.Rows.Add(3, &#34;Suzanne Mathews&#34;, &#34;France&#34;); dt.Rows.Add(4, &#34;Robert Schidner&#34;, &#34;Russia&#34;); GridView1.DataSource = dt; GridView1.DataBind(); } } protected static string ReCaptcha_Key = &#34;key&#34;; protected static string ReCaptcha_Secret = &#34;secret&#34;; [WebMethod] public static string VerifyCaptcha(string response) { string url = &#34;https://www.google.com/recaptcha/api/siteverify?secret=&#34; + ReCaptcha_Secret + &#34;&amp;response=&#34; + response; return (new WebClient()).DownloadString(url); }</pre> <p><span style="text-decoration: underline;">CustomerDetails.aspx.cs</span></p> <pre class="brush: csharp">protected void Page_Load(object sender, EventArgs e) { if (!this.IsPostBack) { lblCustomerId.Text = this.Page.RouteData.Values[&#34;CustomerId&#34;].ToString(); } }</pre> <p><span style="text-decoration: underline;">Screenshot</span></p> <p><span style="text-decoration: underline;"><img src="http://i1030.photobucket.com/albums/y364/dharmendra283/ExcelaSoft/642067.gif" alt="" width="471" height="574" /></span></p>http://www.aspforums.net/Threads/642067/Google-RECaptcha-with-URL-routing-in-ASPNet/http://www.aspforums.net/Threads/642067/Google-RECaptcha-with-URL-routing-in-ASPNet/Thu, 01 Dec 2016 23:13:49 GMT