2011-02-18 47 views

回答

4
  1. 你使用的NuGet?如果你不這樣做,右鍵點擊你的項目的參考部分,選擇廣告庫裝基準
  2. 得到聯機選項卡,並安裝Microsoft的Web助手dll的
  3. 在這個refrence,你會發現一個非常方便的幫手這是ReCaptcha.GetHtml

你可以在你的視圖中使用它,就像下面一樣;

@ReCaptcha.GetHtml(ConfigurationManager.AppSettings["recaptcha-public-key"], "white") 

我把我的recaptcah鍵保存在web.config中,所以我使用ConfigurationManager.AppSettings來連接它們。您可以從http://www.google.com/recaptcha

得到您自己的公鑰和私鑰。在您的控制器中,處理如下的合法呼叫非常容易;

if (ReCaptcha.Validate(ConfigurationManager.AppSettings["recaptcha-private-key"])) { 

//the call is legitimate 

} else { 

// the call is not legitimate 

} 

我希望這有助於。

更新1 Uppps。不要忘記把私鑰和公鑰放在你的_ViewStart.cshtml文件中,如下所示;

@{ 
    Layout = "~/Views/Shared/_Layout.cshtml"; 
    ReCaptcha.PrivateKey = ConfigurationManager.AppSettings["recaptcha-private-key"]; 
    ReCaptcha.PublicKey = ConfigurationManager.AppSettings["recaptcha-public-key"]; 
} 
0

我同意李斯密。我會推薦使用MVCRecaptcha(https://mvcrecaptcha.codeplex.com/)。

您也可以從Nuget下載軟件包,但是請確保您沒有下載其他可用的Recaptcha軟件包 - 您應該專門下載MVC recaptcha。

然後按照MVC recaptcha codeplex網站上的其他說明啓動並運行。

相關問題