Wednesday, November 7, 2012

NoBot Control – Ajax ToolKit Control

 

Introduction :

The name itself specifies it offers protection from bots(robots or any automated software which can submit forms and give reply for messages as humans do). Generally we see using CAPTCHA to prevent entries from ROBOT , we can use this NoBot Control to achieve the same.

Uses :

1)To enhances the site security.( It performing various checks when a form is submitted )
2)To check spam and to prevent hacking to some extent.
3)To perform checks like CAPTCHA.

Attributes :

ResponseMinimumDelaySeconds - Minimum number of seconds to wait before which a postback is considered valid. If postback occurs before this minimum number of seconds , then NoBot state will be "ResponseTooSoon"
CutoffWindowSeconds - It specifies length of cut off window which tracks postbacks within the time specified using this attribute.
CutoffMaximumInstances - Maximum number of postbacks that could occur within in CutOffwindowSeconds.If number of postbacks increases by the number specified in "CutoffMaximumInstances" with in the time limit specified by "CutoffWindowSeconds" , then NoBot State will return "InvalidAddressTooActive"
OnGenerateChallengeAndResponse - Event handler to return NoBot State response.

NoBot Example :

Aspx Code :

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="NoBotControl.aspx.cs" Inherits="Ajax_Controls_Examples_NoBotControl" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>NoBot Control Example</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <ajaxToolkit:ToolkitScriptManager ID="Sc1" runat="server">
        </ajaxToolkit:ToolkitScriptManager>
        <asp:Label ID = "Label1" runat="server" Text="NoBot Message:" Font-Bold="True"></asp:Label>
        <asp:Label ID="Label2" runat="server" Font-Bold="True" ForeColor="Red" ></asp:Label>
        <br /><br />
        <asp:Button ID="btnCheck" runat="server" Text="Check" OnClick="btnCheck_Click" />
        <ajaxToolkit:NoBot ID="NoBot1" runat="server" CutoffWindowSeconds="15"
            ResponseMinimumDelaySeconds="3" CutoffMaximumInstances="4" />
    </div>
    </form>
</body>
</html>

Code Behind :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AjaxControlToolkit;

public partial class Ajax_Controls_Examples_NoBotControl : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnCheck_Click(object sender, EventArgs e)
    {
        NoBotState nbs;
        if (NoBot1.IsValid(out nbs))
        {
            Label2.Text = nbs.ToString();
        }
        else
        {
            Label2.Text = nbs.ToString();
        }
    }
}

Output :

If all the checks are correct , then NoBotState will return “Valid” Message.

Nobot_1

If within the time specified in "ResponseMinimumDelaySeconds" i.e  3 sec , if end user clicks on button more than once , it returns "InvalidResponseTooSoon".

nobot_2


“CutoffMaximumInstances” specifies number of post backs that can occur within time specified in "CutoffWindowSeconds" , so if end user clicks button more than 4 times
within 15 sec , then it returns "InValidAddressTooActive" message.

nobot_3

No comments:

Post a Comment