在 BlogEngine.net 中使用 reCaptcha [英] Using reCaptcha with BlogEngine.net

查看:33
本文介绍了在 BlogEngine.net 中使用 reCaptcha的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚在我的网站上安装了 reCaptcha 并将控制权放在我的评论帖子上,到目前为止一切顺利.

I have just installed reCaptcha on my site and put the control on my comment post, so far so good.

现在要验证 reCaptcha,它说只需执行 Page.IsValid.

Now to validate reCaptcha it says just do Page.IsValid.

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

However BlogEngine uses Ajax and some JS to post its addComment function and if I test that there I just get error on page in the status bar.

这里是bloengine post功能-

Here is the bloengine post function -

/// <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) return;但这从未奏效.

I tried just putting if(!Page.IsValid) return; but that never worked.

推荐答案

现在 1.6.1 内置了对 reCaptcha 的支持看启用 ReCaptcha

Now 1.6.1 has inbuilt support for reCaptcha See Enable ReCaptcha

这篇关于在 BlogEngine.net 中使用 reCaptcha的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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