2

サイトに reCaptcha をインストールし、コメント投稿にコントロールを配置しました。

reCaptcha を検証するには、Page.IsValid を実行するだけです。

ただし、BlogEngine は Ajax といくつかの JS を使用して addComment 関数を投稿します。テストすると、ステータス バーのページにエラーが表示されます。

これがブロエンジンのポスト関数です -

/// <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; だけ入れてみました。しかし、それはうまくいきませんでした。

4

3 に答える 3

2

reCaptchaのデフォルトAPIは、特にreCaptchaが存在するコンテンツを置き換える場合、AJAX駆動型のWebページでは機能しません。ここでの問題は、デフォルトのreCaptchaAPIです。ここでも提供されているAJAXAPIに切り替えるだけです

于 2009-08-17T14:02:54.123 に答える
1
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 を使用しています。でも、考え方は似ていると思います。

お役に立てれば。

于 2009-08-13T19:24:20.577 に答える
0

現在、1.6.1 には reCaptcha のサポートが組み込まれています。「ReCaptcha を有効にする」を参照してください

于 2010-11-07T07:45:16.910 に答える