AjaxControlToolkit NoBotState always InvalidBadResponse

I am trying to implement AjaxControlToolkit NoBot, but always get false from the IsValid() method (the status value is always InvalidBadResponse ). Did I miss something?

ASCX Code:

 // buttons, textboxes etc. <asp:NoBot ID="NoBot1" runat="server" CutoffMaximumInstances="5" CutoffWindowSeconds="60" ResponseMinimumDelaySeconds="2" /> 

Code behind:

 protected void Button1_Click(object sender, EventArgs e) { AjaxControlToolkit.NoBotState state; if (!NoBot1.IsValid(out state)) { Page page = HttpContext.Current.Handler as Page; ScriptManager.RegisterStartupScript(page, page.GetType(), "err_msg", "alert('" + " BOT " + "');", true); } else { ...} } 

Stranger is this: I enter the login information and click the asp button. The NoBot state is InvalidBadResponse and it does not work. But, then I click the update browser button, it asks me to send a request, I say "OK", and now the state is valid! Why?

+8
c # ajaxcontroltoolkit
source share
4 answers

The only reason I know that you will get " InvalidBadResponse " from the NoBot control if javascript is disabled in your browser. The documentation page states that one of the methods used by NoBot is

Forcing the client browser to custom JavaScript to compute and validate the result as part of the postback. (Example: the calculation may be a simple numeric or may also include a DOM for additional assurance that the browser is turned on)

The message " InvalidBadRespone " means that javascript has not been executed (also from the link above):

InvalidBadResponse: An invalid response was provided to the call that the script call was not executing

I would double check your browser settings. I tested this by disabling javascript in my browser (just to make sure)) and tried the example on the documentation page.

You can customize the calculations using the OnGenerateChallengeAndResponse attribute to specify an event handler. I am a good example of implementing one of these event handlers (credit code for this post ):

 protected void PageNoBot_GenerateChallengeAndResponse(object sender, AjaxControlToolkit.NoBotEventArgs e) { Random r = new Random(); int iFirst = r.Next(100); int iSecond = r.Next(100); e.ChallengeScript = String.Format("eval('{0}+{1}')", iFirst, iSecond); e.RequiredResponse = Convert.ToString(iFirst + iSecond); } 
+2
source share

As mentioned in other answers, InvalidBadResponse is due to Javascript failure.

Problem:

The reason it was unsuccessful for me was because the ajax libraries for ASP.NET needed to run did not load; take a look at your javascript debugger browser; this is what mine (in Chrome) looked like

enter image description here

As you can see, the .axd files .axd not serviced, and the ASP.NET Ajax client-side framework failed to load error was quite complicated.

Reason: (in my case)

I had a url rewrite rule that accidentally changed the .axd , which caused them to not be served.

I would recommend checking your web.config , add a line if necessary

 <add input="{URL}" pattern="\.axd$" negate="true"/> 

to your rules and this

 routes.Ignore("{resource}.axd/{*pathInfo}"); 

in your Global.asax (if you have one), where (and if) you are registering routes.

Check this SO answer: On the Ajax client side, Asp.Net 4.0 failed to load

0
source share

Another possible reason might be the ViewStateMode of the wizard, page, or control set to Disabled. It seems that for NoBot to work correctly, Enabled must be enabled.

I did some tests with ViewStateMode = "Disabled" on my CMS main page, and NoBotState started returning InvalidBadResponses on my login page. Changing it to ViewStateMode = "Enabled" is fixed for me.

0
source share

All Articles