alireza.wise
سه شنبه 16 دی 1393, 10:09 صبح
با عرض سلام
دوستان گرامی بنده در پروژه ام میخواستم از کپچا گوگل استفاده کنم و از کدهای زیر استفاده کردم ولی مشکل اینجاست که در قسمت ویوی Get نمیتونم Add View کنم تا کدهای ویو رو داخلش بگذارم. به نظرتون مشکل کجاست و باید چکار کنم.
پیشایش تشکر میکنم
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.UI;
using System.Web.UI.WebControls;
using Recaptcha;
namespace Project.Web.Controllers
{
public class CaptchaValidatorAttributeController : ActionFilterAttribute
{
private const string CHALLENGE_FIELD_KEY = "recaptcha_challenge_field";
private const string RESPONSE_FIELD_KEY = "recaptcha_response_field";
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
var captchaChallengeValue = filterContext.HttpContext.Request.Form[CHALLENGE_FIELD_KEY];
var captchaResponseValue = filterContext.HttpContext.Request.Form[RESPONSE_FIELD_KEY];
var captchaValidtor = new Recaptcha.RecaptchaValidator
{
PrivateKey = "6Lc-_P8SAAAAAOy37Z-5A_UaoWZBqeUzqPIE_vou",
RemoteIP = filterContext.HttpContext.Request.UserHostAddress,
Challenge = captchaChallengeValue,
Response = captchaResponseValue
};
var recaptchaResponse = captchaValidtor.Validate();
// this will push the result value into a parameter in our Action
filterContext.ActionParameters["captchaValid"] = recaptchaResponse.IsValid;
base.OnActionExecuting(filterContext);
}
[RecaptchaControlMvc.CaptchaValidatorAttribute]
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult CreateComment(Int32 id, bool captchaValid)
{
return View();
}
[AcceptVerbs(HttpVerbs.Get)]
public ActionResult CreateComment()
{
return View();
}
public static string GenerateCaptcha(HtmlHelper helper)
{
var captchaControl = new Recaptcha.RecaptchaControl
{
ID = "recaptcha",
Theme = "blackglass",
PublicKey = "6Lc-_P8SAAAAAPad3gjroSTvuAo4juTz5daQnVL5",
PrivateKey = "6Lc-_P8SAAAAAOy37Z-5A_UaoWZBqeUzqPIE_vou"
};
var htmlWriter = new HtmlTextWriter(new StringWriter());
captchaControl.RenderControl(htmlWriter);
return htmlWriter.InnerWriter.ToString();
}
}
}
دوستان گرامی بنده در پروژه ام میخواستم از کپچا گوگل استفاده کنم و از کدهای زیر استفاده کردم ولی مشکل اینجاست که در قسمت ویوی Get نمیتونم Add View کنم تا کدهای ویو رو داخلش بگذارم. به نظرتون مشکل کجاست و باید چکار کنم.
پیشایش تشکر میکنم
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.UI;
using System.Web.UI.WebControls;
using Recaptcha;
namespace Project.Web.Controllers
{
public class CaptchaValidatorAttributeController : ActionFilterAttribute
{
private const string CHALLENGE_FIELD_KEY = "recaptcha_challenge_field";
private const string RESPONSE_FIELD_KEY = "recaptcha_response_field";
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
var captchaChallengeValue = filterContext.HttpContext.Request.Form[CHALLENGE_FIELD_KEY];
var captchaResponseValue = filterContext.HttpContext.Request.Form[RESPONSE_FIELD_KEY];
var captchaValidtor = new Recaptcha.RecaptchaValidator
{
PrivateKey = "6Lc-_P8SAAAAAOy37Z-5A_UaoWZBqeUzqPIE_vou",
RemoteIP = filterContext.HttpContext.Request.UserHostAddress,
Challenge = captchaChallengeValue,
Response = captchaResponseValue
};
var recaptchaResponse = captchaValidtor.Validate();
// this will push the result value into a parameter in our Action
filterContext.ActionParameters["captchaValid"] = recaptchaResponse.IsValid;
base.OnActionExecuting(filterContext);
}
[RecaptchaControlMvc.CaptchaValidatorAttribute]
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult CreateComment(Int32 id, bool captchaValid)
{
return View();
}
[AcceptVerbs(HttpVerbs.Get)]
public ActionResult CreateComment()
{
return View();
}
public static string GenerateCaptcha(HtmlHelper helper)
{
var captchaControl = new Recaptcha.RecaptchaControl
{
ID = "recaptcha",
Theme = "blackglass",
PublicKey = "6Lc-_P8SAAAAAPad3gjroSTvuAo4juTz5daQnVL5",
PrivateKey = "6Lc-_P8SAAAAAOy37Z-5A_UaoWZBqeUzqPIE_vou"
};
var htmlWriter = new HtmlTextWriter(new StringWriter());
captchaControl.RenderControl(htmlWriter);
return htmlWriter.InnerWriter.ToString();
}
}
}