首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在BlogEngine.net中使用reCaptcha

在BlogEngine.net中使用reCaptcha
EN

Stack Overflow用户
提问于 2009-08-11 13:53:40
回答 3查看 2.1K关注 0票数 2

我刚刚在我的网站上安装了reCaptcha,并将控件放在了我的评论帖子上,到目前为止一切都很好。

现在,为了验证reCaptcha,它说只需执行Page.IsValid。

然而,BlogEngine使用Ajax和一些JS来发布它的addComment函数,如果我在那里测试,我只会在状态栏中的页面上得到错误。

这里是bloengine post函数-

代码语言:javascript
复制
/// <summary>
/// Processes a callback event that targets a control.
/// </summary>
/// <param name="eventArgument">A string that represents an event argument to pass to the event handler.</param>
public void RaiseCallbackEvent(string eventArgument)
{
    if (!BlogSettings.Instance.IsCommentsEnabled)
        return;

    string[] args = eventArgument.Split(new string[] { "-|-" }, StringSplitOptions.None);
    string author = args[0];
    string email = args[1];
    string website = args[2];
    string country = args[3];
    string content = args[4];
    bool notify = bool.Parse(args[5]);
    bool isPreview = bool.Parse(args[6]);
    string sentCaptcha = args[7];
    //If there is no "reply to" comment, args[8] is empty
    Guid replyToCommentID = String.IsNullOrEmpty(args[8]) ? Guid.Empty : new Guid(args[8]);

    string storedCaptcha = hfCaptcha.Value;

    Comment comment = new Comment();
    comment.Id = Guid.NewGuid();
    comment.ParentId = replyToCommentID;
    comment.Author = Server.HtmlEncode(author);
    comment.Email = email;
    comment.Content = Server.HtmlEncode(content);
    comment.IP = Request.UserHostAddress;
    comment.Country = country;
    comment.DateCreated = DateTime.Now;
    comment.Parent = Post;
    comment.IsApproved = !BlogSettings.Instance.EnableCommentsModeration;

    if (Page.User.Identity.IsAuthenticated)
        comment.IsApproved = true;

    if (website.Trim().Length > 0)
    {
        if (!website.ToLowerInvariant().Contains("://"))
            website = "http://" + website;

        Uri url;
        if (Uri.TryCreate(website, UriKind.Absolute, out url))
            comment.Website = url;
    }

    if (notify && !Post.NotificationEmails.Contains(email))
        Post.NotificationEmails.Add(email);
    else if (!notify && Post.NotificationEmails.Contains(email))
        Post.NotificationEmails.Remove(email);

    if (!isPreview)
    {
        Post.AddComment(comment);
        SetCookie(author, email, website, country);
    }

    string path = Utils.RelativeWebRoot + "themes/" + BlogSettings.Instance.Theme + "/CommentView.ascx";

    CommentViewBase control = (CommentViewBase)LoadControl(path);
    control.Comment = comment;
    control.Post = Post;

    using (StringWriter sw = new StringWriter())
    {
        control.RenderControl(new HtmlTextWriter(sw));
        _Callback = sw.ToString();
    }
}

我试着只返回if(!Page.IsValid),但是从来没有成功过。

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2010-11-07 15:45:17

现在1.6.1已经内置了对reCaptcha的支持,请参阅Enable ReCaptcha

票数 0
EN

Stack Overflow用户

发布于 2009-08-17 14:02:54

reCaptcha的默认API不适用于AJAX驱动的网页,尤其是当您替换reCaptcha所在的内容时。这里的问题是默认的reCaptcha应用编程接口。只需切换到AJAX API,它也提供here

票数 2
EN

Stack Overflow用户

发布于 2009-08-13 19:24:21

代码语言:javascript
复制
var captchaChallengeValue = filterContext.HttpContext.Request.Form["recaptcha_challenge_field"];
var captchaResponseValue = filterContext.HttpContext.Request.Form["recaptcha_response_field"];
var captchaValidator = new Recaptcha.RecaptchaValidator
{
    PrivateKey = "private key here",
    RemoteIP = filterContext.HttpContext.Request.UserHostAddress,
    Challenge = captchaChallengeValue,
    Response = captchaResponseValue
};

var recaptchaResponse = captchaValidtor.Validate();

这就是我在另一个网站上做的事情。我获得了输入的内容和响应,然后创建了一个新的captchaValidator,它有一个检查响应是否有效的方法。然后使用它作为if的布尔值。

我使用的是ASP.Net MVC。但是,我会假设这个想法是相似的。

希望这能有所帮助。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1260525

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档