[英]Google reCAPTACHA - hosted in IIS - Server responded with a status of 503 (Service Unavailable) - MVC5
我使用MVC-Ajax將Google reCAPTCHA集成到我的注冊頁面中。
我可以在本地主機中提交reCAPTACHA。 但是在我部署到服務器后-出現“服務不可用503”錯誤。 我對localhost和demo.com有不同的密鑰
部署后,我的代碼沒有任何變化。 我剛剛從config更新了我的Google reCAPTACHA密鑰。 當表單提交操作獲取服務不可用錯誤時。
這是我的index.cshtml頁面代碼
<form id="reg-form" class="col-sm-6 col-sm-offset-3" action="@Url.Action("Submit","Registration")" method="post" novalidate>
<div class="form-group">
<label class="control-label" for="reg-name">Enter your name:</label>
<div class="regs">
<input id="FullName" name="FullName" class="form-control" type="text" data-error-empty="Please enter your name">
<i class="fa fa-user"></i>
</div>
</div><!-- End Name input -->
<div class="form-group">
<div id='recaptcha' class="g-recaptcha" data-error-empty="The captcha field is required."
data-sitekey="publicKeyfromGooglereCAPTACHA"></div>
</div>
<p>
<button name="submit" type="submit" class="btn btn-qubico btn-block g-recaptcha"
data-error-message="Fill out all information above!" data-sending-message="Sending..." data-ok-message="Message Sent"
data-callback="onSubmit">
<i class=" fa fa-location-arrow">
</i>Submit
</button>
</p> </form>
這是我的Registration.cs控制器
[HttpPost]
[System.Web.Services.WebMethod]
public JsonResult Submit(FormCollection formcollection)
{
try
{
int status = 0;
form.FullName = formcollection["FullName"];
CaptchaResponse response = ValidateCaptcha(Request["g-recaptcha-response"]);
if (response.Success)
{
status = 1;
}
else
{
status = 0;
}
return Json(status);
}
catch (Exception ex)
{
return Json(ex.Message + ex.InnerException.Message);
}
}
[HttpPost]
/// <summary>
/// Validate Captcha
/// </summary>
/// <param name="response"></param>
/// <returns></returns>
public static CaptchaResponse ValidateCaptcha(string response)
{
string secret = System.Web.Configuration.WebConfigurationManager.AppSettings["recaptchaPrivateKey"];
var client = new WebClient();
var jsonResult = client.DownloadString(string.Format("https://www.google.com/recaptcha/api/siteverify?secret={0}&response={1}", secret, response));
return JsonConvert.DeserializeObject<CaptchaResponse>(jsonResult.ToString());
}
這是我的模型CaptchaResponse.cs-
public class CaptchaResponse
{
[JsonProperty("success")]
public bool Success
{
get;
set;
}
[JsonProperty("error-codes")]
public List<string> ErrorMessage
{
get;
set;
}
}
這是我的jQuery腳本
$(document).ready(function () {
$('#reg-form').submit(function () {
$.ajax({
type: "POST",
url: "Registration/Submit",
data: formInput,
dataType: "json",
success: function (data) {
console.log(JSON.stringify(data));
},
error: function (data) {
console.log(JSON.stringify(data));
}
});
}
return false;
});
});
這是我的web.config代碼
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
<add key="reCaptchaPublicKey" value="publicKeyfromGooglereCAPTACHA" />
<add key="reCaptchaPrivateKey" value="privateKeyfromGooglereCAPTACHA" />
注意 :應用程序托管在https端口。
讓我知道是否需要更多詳細信息。
此問題已解決。 我在配置文件中添加了以下幾行。
<handlers>
<add name="MSCaptcha" verb="GET" path="/CaptchaImage.axd" type="MSCaptcha.captchaImageHandler, MSCaptcha"/>
</handlers>
或使用以下步驟添加處理程序
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.