NoCaptcha in SalesForce Web to Lead - asp.net

I've got an legacy Umbraco ASP.NET site (v4.7) which I've been requested to place a SalesForce web to sales form on it. I've done this and all is well apart from the amount of spam that's getting through.
So I'm trying to use the Google NoCaptcha widget which I've successfully placed on the form but I don't know how to validate the response. All of the examples I've searched are using PHP cURL method which I cannot use.
To further complicate things the site is compiled and I've don't have access to the source files so I can't create any controls/classes, etc. in the solution.
Is it possible to validate the recaptcha response using only the 'client' (javascript for example) with no back end processing done?
Any help would be greatly appreciated.
Thanks,
Craig

set the enabled property of the button to false.
<asp:button id="btnName" enabled="false" text="submit" />
and then on the recaptcha container:
<div id="asd" class="g-recaptcha" data-callback="EnableButton" data-expired-callback="DisableButton" data-sitekey="your-site-key">
</div>
where data-callback and data-expired-callback are events of the widget.
data-callback:
invoked after a successful captcha
data-expired-callback:
invoked when session times out.
where EnableButton and DisableButton are javascript functions which does exactly what they say they do.
<script type="text/javascript">
var DisableButton = function () {
alert("Confirmation Expired. Please Answer Recaptcha.");
document.getElementById('<%=btnName.ClientID %>').disabled = true;
grecaptcha.reset();
};
var EnableButton = function () {
document.getElementById('<%=btnName.ClientID %>').disabled = false;
};
</script>
but it is really recommended to still verify it on server-side.
hope it helps..

Related

Avoid viewstate to display on website source code

I have performance issue on website, because of too long viewstate in source code. on some pages it's size is more than 15-20kb. Which is increasing the load time on browser.
Is there any way to disable viewstate partially or fully without any harm on other module of website. FYI there is one listview and one form on these example pages. where viewstate is very long.
More Example pages
http://www.pricingindia.in/coupons/ebay-in-coupon-codes-20
http://www.pricingindia.in/coupons/flipkart-coupon-codes-32
You probably want to disable for ViewState for your Page in general, and then only enable ViewState for the controls that need / use it.
See this MSDN page on the Control.ViewStateMode property, it describes how to set that up:
To disable view state for a page and to enable it for a specific
control on the page, set the EnableViewState property of the page and
the control to true, set the ViewStateMode property of the page to
Disabled, and set the ViewStateMode property of the control to
Enabled.
You will need to do some testing to see which controls need / use the ViewState in your specific app. But, basically,
anything that's static, you can disable the ViewState (Buttons, LinkButtons, etc).
Any controls whose state doesn't need to be restored between PostBacks, you can disable ViewState (such as a TextBox in a form that is submitted to the server, and then cleared).
Any controls that need to keep their state between PostBacks, you want to enable Viewstate (this would often be databound controls like GridViews / etc).
Doing this should definitely reduce the load that ViewState is putting on your pages.
Okay, I couldn't leave well enough alone:
Firebug said the following bit of code blocked the site from rendering for about 6 seconds. I thought it was the jsapi (based on info from chrome's tools) but the following returned a "502 Bad Gateway" message meaning that it sat there spinning it's wheels unable to process while preventing your web page from displaying.
I would move the <script .. call to the header, where it belongs. Then I'd move the google.load and google.setOnLoadCallback to the bottom of the web page so it runs last.
Finally I'd figure out exactly why it's failing to work right.
Homework for you: get Firebug loaded into firefox and learn how to use it's Net tools to see where site loading issues are.
<div class="sr_bx1 FL clearfix">
<div class="FL searchbg">
<div id='cse' style='width: 100%;'>Loading</div>
<script src='http://www.google.com/jsapi' type='text/javascript'></script>
<script type='text/javascript'>
google.load('search', '1', { language: 'en', style: google.loader.themes.V2_DEFAULT });
google.setOnLoadCallback(function () {
var customSearchOptions = {};
var orderByOptions = {};
orderByOptions['keys'] = [{ label: 'Relevance', key: '' }, { label: 'Date', key: 'date'}];
customSearchOptions['enableOrderBy'] = true;
customSearchOptions['orderByOptions'] = orderByOptions;
var imageSearchOptions = {};
imageSearchOptions['layout'] = 'google.search.ImageSearch.LAYOUT_POPUP';
customSearchOptions['enableImageSearch'] = true;
customSearchOptions['overlayResults'] = true;
var customSearchControl = new google.search.CustomSearchControl('010882286766777081969:xkox132izzk', customSearchOptions);
customSearchControl.setResultSetSize(google.search.Search.FILTERED_CSE_RESULTSET);
var options = new google.search.DrawOptions();
options.setAutoComplete(true);
customSearchControl.draw('cse', options);
}, true);
</script>
</div>
Using Page Adapter Class, you can solve this problem. I found following solution helpful for ASP.NET Web Application:
view state serialization is handled by an object of type PageStatePersister. (The PageStatePersister class is an abstract class that defines the base-level functionality for serializing view state to some persistent medium.)
Steps:
1) In Your Web Application, Add Folder: App_Browsers
2) In this folder, Add new BrowserFile: ViewStateAdapter.browser
3) Write following code in it:
<browsers>
<browser refID="Default">
<controlAdapters>
<adapter controlType="System.Web.UI.Page" adapterType="ServerSideViewStateAdapter" />
</controlAdapters>
</browser>
</browsers>
4) In Your WebApplication, Add Folder: App_Code
5) In this folder, Add new ClassFile: ServerSideViewStateAdapter.cs
6) Write following code in it:
using System;
using System.Web.UI;
using System.Web.UI.Adapters;
public class ServerSideViewStateAdapter : PageAdapter
{
public override System.Web.UI.PageStatePersister GetStatePersister()
{
return new SessionPageStatePersister(this.Page);
}
}
You can refer this video, it can help you:
https://www.youtube.com/watch?v=36pmFySbXZA

add RESTfull capabilities to meteor

Whatever the path entered in the browser, the meteor app always returns a template. How can one add routing to enable RESTfull capabilities in a meteor app?
in my quest to add RESTfull capabilities to my meteor app, I cam accross meter-router which is a great meteorite smart package.
here is a short explanation on how to get it and how to access the body part of a POST:
meteor will add RESTfull capabilities before the 1.0 release. In the mean time, you have to use meter-router. This
article explains how to do that.
Follow the instructions in meteor-router
In the server-side routing part, it is not explained how to get to the parameters in the request body. This took me
some time to figure out so here it is:
assuming you use the following form:
<form action="http://localhost:3000/test" method="POST">
<input value="titi" name="testme"/>
<input type="submit" />
</form>
The content of the testme field will be located in this.request.body.testme. Here is a sample that will return some text with the content of the field
if (Meteor.isServer) {
Meteor.startup(function () {
Meteor.Router.add('/test', 'POST', function () {
return "called with "+ this.request.body.testme + "\n";
});
});
}
meteor-collectionapi may suite your needs. It adds a wrapper around your collections in order to expose them via REST.

Notify a facebook user if a comment is made using the <fb:Comments> comment box

I have an application on facebook and i have the facebook comment box on it. If someone makes a comment using the comment box, is there a way to notify person that a post has been made on their app
I have the following code
<script src="https://connect.facebook.net/en_US/all.js#xfbml=1"></script>
<fb:comments xid="test" canpost="true" candelete="false" href="<%= link %>" num_posts="10" width="500" send_notification_uid="<%= fbUserId %>" notify="true" publish_feed="true"></fb:comments>
The href - link is a dynamic link depending on where the post was made. The send_notification_uid - user_Id is also dynamic and it retrieves the user id of the person that owns the page.
Any help would be great. It all works apart from the send notification
I believe using the javascript SDK you can subscribe to the comment.create event. Then provided you have the necessary permissions for the uid in question, you could then send them a notification I believe. I haven't tested this but you need to look at the FB.event.subscribe code
https://developers.facebook.com/docs/reference/javascript/FB.Event.subscribe/
There's some more information on a post here
http://facebook.stackoverflow.com/questions/6146925/fb-event-subscribecomment-create-doesnt-work
Further to this you can test things out on the js skd tool
https://developers.facebook.com/tools/console/
and some sample code
<h1>Defaults</h1>
<fb:comments href="http://www.fbrell.com/"></fb:comments>
<script>
FB.Event.subscribe('comments.add', function(resp) {
console.log('Comment was added' + resp);
});
</script>
I don't know if the specs changed, but the current answer doesn't work anymore, the new way is now this :
FB.Event.subscribe('comment.create', function() {
console.log('Comment was added');
console.log(arguments);
});
comment.create , as explained here : https://developers.facebook.com/docs/reference/javascript/FB.Event.subscribe/v2.0#comments-example

ClientId is different in localhost and the webserver

I am facing a new kind of problem.
I am using the jQuery to fill the state dropdown on the change of country dropdown and the code of the jquery is on a js file so i bind the static client id like ct100_ddlCountry, this is working properly on the localhost but when i host this website to web server it not working because the client generating on the server is _ct100_ddlCountry.
Please tell me something if anyone has an idea about this. I am new to this kind of problem.
Thanks to all.
If you can't upgrade to .NET 4.0 for clean id's, I wrote a small lib and shoved it on CodePlex to serialize controls to a JSON array on the client.
http://awesomeclientid.codeplex.com/
http://www.philliphaydon.com/2010/12/i-love-clean-client-ids-especially-with-net-2-0/
It serializes the controls and outputs some JavaScript like:
<script type=”text/javascript”>
//<![CDATA[
var controls = {
"txtUserName": "ctl00_ContentPlaceHolder1_txtUserName",
"txtEmail": "ctl00_ContentPlaceHolder1_txtEmail",
"btnSubmit": "ctl00_ContentPlaceHolder1_btnSubmit"
};
//]]>
</script>
Which then allows you to access controls like:
<script type=”text/javascript”>
//<![CDATA[
var element = document.getElementById(controls.btnSubmit);
//]]>
</script>
No need to write spaghetti code :)
Edit: Alternatively, you can use jQuery selectors to do something like:
var control = $('[id*=txtEmail]');
It is not normally good practice to hard code control ids in your js script includes or html source.
Try using something like this:
JS
function DoChange(controlid) {
$("#"+controlid);
}
HTML
<select onchange='DoChange("<%= ddlCountry.ClientID %>");' />
It means if you move your control around in your control tree, then you dont break your code, and it should work on your localhost and IIS
UPDATE
Or like this
JS
function DoChange(control) {
$(control);
}
HTML
<select onchange="DoChange(this);" />
If it is ASP.Net 4.0 then you can use ClientIDMode="Static" to make sure that only IDs provided by you are there on final markup.
Or you can use something like $('id$=country'). $ is used to match the end of Id, but I am sure that is something not optimal.

Displaying Loading text while doing a WebRequest

I have a button on my webform. Clicking this button will do an HttpWebRequest during the onclick event handler. After the request we copy the response from the request into HttpContext.Current.Response and send that to the client.
This web request can take a while (up to 5 seconds, since it's generating a report). During this time the user has no indication that anything is going on, except for the browser progress bar and the spinning IE icon (if they're using IE). So I need a loading indicator while this is happening.
I've tried using javascript that fires during the button's onclick event (using OnClientClick) and while that works, I don't know how to find out when the web request is finished. Since we just send the response to the client, a full postback doesn't happen.
I've tried wrapping the button in an UpdatePanel and using the UpdateProgress, but when we send the response to HttpContext.Current.Response and call Response.End(), we get an error in the javascript, since the response isn't well formed (we're sending back an excel sheet for the user to download).
Since we're sending back a file for users to download, I don't want to pop-up a separate window, since then in IE they'd get the information bar blocking the download.
Any ideas here?
As an alternative to the Professional AJAX.NET library, jQuery has a really nice way of doing this.
Take a look at this example of using a .NET PageMethod (if possible in your scenario).
You define a page method call in jQuery, you can tack on your loading... message in a hidden div.
Say what callback you want to return on success (ie when your 5 second report is generated)
then hide the loading and handle the data.
Take a look at the javascript on my contact page for an example (view the source).
I have a a button on the page, add the jQuery onClick.
When clicked that shows a hidden loading div, makes an ajax call to a page method that takes the parameters of the form.
The page method does emailing etc then returns to the form in the onSuccess javascript method I have there.
The onSuccess hides the loading div.
A simple trick i have used in the past is to redirect to an intermediate page with an animated progress bar (gif) and then have that page do the REAL post of the data.
(or even pop-up a layer with the animation on it and a polite message asking the user to wait a minute or two)
The simple feedback of the animated gif creates the illusion to the end user that the app is not stalled and they will be more patient.
Another approach is to hand the data off to a worker thread and return immediately with a message stating that the report will be emailed or made available in the "reports" section of the site when it is ready. This approach lacks the benefit of instant notification when the report is completed though.
Here is my solution :
Download and examine the samples of free Professional AJAX.NET library.
Write a AjaxMethod that creates your file and returns file location as a parameter.
Write your Client-Side function to call method at Step 2. When this method called show an indicator.
Write a client-side callback method to hide indicator and show/download file that user requested.
Add your client-side function calls yo your button element.
When your method at server-side ends your callback will be called.
Hope this helps !
The solution I'm presenting here is aimed to show a method to let a "Loading..." box to appear while you're server-side processing and to disappear when server-side processing is complete.
I'll do this with the very basic AJAX machinery (tested on FF, but IE should be ok either), i.e. not using a framework like Prototype or jQuery or Dojo, as you didn't specify your knowledge about them.
To let you better understand the trick, the following is just a small example and doesn't pretend to be an out-of-the-box solution. I tend not to be superficial, but I think a clearer example can explain better than many words.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>First Example</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<style>
.hidden {
display: none;
}
.loadingInProgress {
color: #FFFFFF;
width: 75px;
background-color: #FF0000;
}
</style>
<script type="text/javascript">
var httpRequest;
if (window.XMLHttpRequest) { // Mozilla, Safari, ...
httpRequest = new XMLHttpRequest();
httpRequest.overrideMimeType('text/xml');
} else if (window.ActiveXObject) { // IE
try {
httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e) {
try {
httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e) {}
}
}
if (!httpRequest) {
alert('Giving up :( Cannot create an XMLHTTP instance');
}
httpRequest.onreadystatechange = function(){
switch (httpRequest.readyState) {
case 1: // Loading
document.getElementById('loading').className = "loadingInProgress";
break;
case 4: // Complete
document.getElementById('loading').className = "hidden";
if (httpRequest.status == 200) {
// perfect!
} else {
// there was a problem with the request,
// for example the response may be a 404 (Not Found)
// or 500 (Internal Server Error) response codes
}
break;
}
};
function go() {
httpRequest.open('GET', document.getElementById('form1').action, true);
httpRequest.send('');
}
</script>
</head>
<body>
<div id="loading" class="hidden">Loading...</div>
<form id="form1" name="form1" action="doSomething.php">
<input type="button" value="Click to submit:" onclick="go()" />
</form>
</body>
</html>
As you can see, there's a <div> which holds the "Loading..." message.
The principle is to show/hide the <div> depending on the XMLHttpRequest object's readyState.
I've used the onreadystatechange handler of the XMLHttpRequest to trigger the readyState change.
The back-end php script I use (declared as the form's action) does just a sleep(5), to let the "Loading..." message appear for 5 secs.
<?php
sleep(5);
header('Cache-Control: no-cache');
echo "OK";
?>
The Cache-control: no-cache header is necessary, since usually if you don't set it the browser will cache the response avoiding to resubmit the request if you should need to.
A good source for "getting started" AJAX documentation is Mozilla MDC.
The whole thing could be much more gently handled by a Javascript framework like Prototype, taking advantage of its browser-safe approach, saving you hours of debug.
Edit:
I chose php 'cause I don't know ASP.NET nor ASP, sorry about that.

Resources