AjaxControlToolkit NoBotState总是InvalidBadResponse [英] AjaxControlToolkit NoBotState is always InvalidBadResponse

查看:289
本文介绍了AjaxControlToolkit NoBotState总是InvalidBadResponse的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现AjaxControlToolkit NoBot但我总是得到假的IsValid()办法(状态值始终 InvalidBadResponse )。 ?我失去了一些东西在这里。

I am trying to implement AjaxControlToolkit NoBot but I always get false from IsValid() method (the state value is always InvalidBadResponse). Am I missing something here?

ASCX代码:

// 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
    { ...}
}

更奇怪的是这样的:我为登录输入数据并点击按钮的ASP。 NoBot状态是 InvalidBadResponse 和失败。但是,后来我在浏览器的刷新按钮,点击它要求我重新发送请求,我说OK,现在的状态是有效的!为什么呢?

Far more weird is this: I enter data for login and click on asp button. NoBot state is InvalidBadResponse and it fails. But, then I click on browser's refresh button it asks me to resend request I say ok and now state is valid! Why?

推荐答案

我所知道的唯一的原因,你会得到一个 InvalidBadResponse NoBot 控制,如果你有浏览器的JavaScript禁用。该文档页面指出,由<$ C $使用的技术之一C> NoBot 是

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

强制客户端的浏览器进行配置JavaScript
计算和验证结果作为回发的一部分。 (例如:在
计算可以是一个简单的数字,或者也可以包括用于加入保证一个浏览器所涉及的DOM $ B $二)

Forcing the client's browser to perform a configurable JavaScript calculation and verifying the result as part of the postback. (Ex: the calculation may be a simple numeric one, or may also involve the DOM for added assurance that a browser is involved)

这是 InvalidBadRespone 消息意味着JavaScript的没有得到(也是从上面的链接)执行:

An "InvalidBadRespone" message means that the javascript did not get executed (also from the link above):

InvalidBadResponse:的无效响应这一挑战
暗示的挑战脚本无法运行。

InvalidBadResponse: An invalid response was provided to the challenge suggesting the challenge script was not run

我会仔细检查浏览器设置。我已经在我的浏览器(只是为了确保)禁用JavaScript和尝试文档页的示例测试这一点。

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

您可以使用自定义计算 OnGenerateChallengeAndResponse 属性来指定事件处理程序。我好实现一个这样的事件处理程序的例子是这样的(代码信贷的这个帖子):

You can customize the calculation using the OnGenerateChallengeAndResponse attribute to specify an Event Handler. I good example of implementing one such event handler is this (code credit to 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);  
}

这篇关于AjaxControlToolkit NoBotState总是InvalidBadResponse的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆