2015-04-02 77 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)