2015-04-02 70 views
-1

我使用PoliteCaptcha如下:PoliteCaptcha的Https問題MVC剃刀

<div class="form-container"> 
@using (Html.BeginForm("LogOn", "Account", new { ReturnUrl = Request.QueryString["ReturnUrl"] }, FormMethod.Post, new { id = "formLogOn" })) 
{ 
    @Html.TextBoxFor(model => model.UserId, new { id = "textBoxUserId", placeholder="Enter your username" })<br /> 
    @Html.ValidationMessageFor(model => model.UserId)<br /> 

    @Html.PasswordFor(model => model.Password, new { placeholder="Enter your password" })<br /> 
    @Html.ValidationMessageFor(model => model.Password)<br /> 

    @Html.SpamPreventionFields() 

    <input type="submit" id="ButtonLogOn" value="LoginButton" class=" button" /> 
} 
</div> 
<div id="validationSummary"> 
    @Html.Partial("_AjaxValidationSummaryPartial") 
</div> 

@if (Model != null && !Model.ShowCatcha) 
{ 
    @Html.SpamPreventionScript() 
} 

這工作得很好,但是當它在一個HTTPS域變爲不活。 我得到錯誤:

Mixed Content: The page at ' https://www.domain.com/log?ReturnUrl=%2Fadmin ' was loaded over HTTPS, but requested an insecure script ' http://www.google.com/recaptcha/api/challenge?k=6LcAAAAOQuMiKA-yCo4HZPp4gy-T0x7CaX '. This request has been blocked; the content must be served over HTTPS.

+0

有沒有辦法用「https://www.google.com/recaptcha/」(httpS:)取代「http://www.google.com/recaptcha/」? – TTT 2015-04-29 09:41:01

+2

嘗試搜索,而不是等待三週並添加賞金:[爲什麼我突然在Firefox中獲得「阻止加載混合活動內容」問題?](http://stackoverflow.com/questions/18251128/why-am-i - 如何修復一個阻止混合內容的網站](https://developer.mozilla.org/en-US/)文檔/安全/ MixedContent/How_to_fix_website_with_mixed_content)。 – CodeCaster 2015-04-29 09:49:51

+0

[用於MVC 4和5的Nuget Google reCAPTCHA](https://www.nuget.org/packages/reCAPTCH.MVC/)和[Demo and Document](http://recaptchamvc.apphb.com/) – Sender 2015-06-19 13:55:48

回答

1

你需要從一個安全的連接不安全的內容,而這通常是強烈反對。

我檢查了PoliteCaptcha源代碼,並沒有引用JS文件;出於這個原因,它應該很容易修復。

找到您的腳本標記並簡單地刪除協議前綴。

更改此

<script src="http://www.google.com/recaptcha.js

對此

<script src="//www.google.com/recaptcha.js

瀏覽器會自動計算出使用的協議,並擺脫問題。

+0

再次檢查 https://github.com/NuGet/PoliteCaptcha/search?utf8=%E2%9C%93&q=RenderControl。最終請撥打此https://code.google.com/p/recaptcha/source/browse/trunk/recaptcha-plugins/dotnet/library/RecaptchaControl.cs#358 – JJS 2015-05-04 00:09:14

0

您很可能背後是一個反向代理,並且RecaptchaControl用來生成腳本的api沒有正確檢測到Context.Request.IsSecureConnection。 你能告訴我們Context.Request.IsSecureConnection返回什麼值嗎?

https://code.google.com/p/recaptcha/source/browse/trunk/recaptcha-plugins/dotnet/library/RecaptchaControl.cs#358

@ Html.SpamPreventionFields()是一個IHtmlString,所以你可以只創建一個頁面變量,做一些關於它的String.Replacing ...

@{ 
var preventionFields = Html.SpamPreventionFields().ToHtmlString().Replace("http:", "https:") 
} 

,並在您的形式

@Html.Raw(preventionFields)