C#MVC3:加载网站通过HTTPS无法加载的reCAPTCHA安全code。 Chrome的调试器给出了一个"混合内容错误" [英] C# MVC3: website loaded over HTTPS cannot load recaptcha security code. Chrome debugger gives a "Mixed Content error"

查看:633
本文介绍了C#MVC3:加载网站通过HTTPS无法加载的reCAPTCHA安全code。 Chrome的调试器给出了一个"混合内容错误"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个C#MVC应用程序,使得使用验证码安全code在特定视图。
在我看来,我有以下code:

I have a C# MVC app that makes use of recaptcha security code in a particular view. In my view i have the following code:

<script type="text/javascript" src="https://www.google.com/recaptcha/api/js/recaptcha_ajax.js"></script>
...
@Html.Raw(Html.GenerateCaptcha("captcha", "white"))
@Html.ValidationMessage("captcha")

当我尝试加载页面时,我得到以下错误在Chrome的调试器:

When i try to load the page, i get the following error in chrome's debugger:

Mixed Content: The page at 'https://mywebsite.com' was loaded over HTTPS, but requested an insecure resource 'http://www.google.com/recaptcha/api/challenge?k=mykey'. This request has been blocked; the content must be served over HTTPS.

如果我检查加载页面的源代码,为验证码剃刀控制生成此脚本标签:

and if i inspect the source of the loaded page, the razor control for recaptcha generates this script tag:

<script type="text/javascript" src="http://www.google.com/recaptcha/api/challenge?k=mykey">

src属性是一个HTTP URL不是一个HTTPS URL。

the src attribute is a http url not a https url.

如果有人知道我怎么可以克服这个错误,那将是极大的AP preciated。
谢谢,
KAPETANIOS

If anyone knows how i can overcome this error, it would be greatly appreciated. Thanks, Kapetanios

推荐答案

好吧我在这里再次发布的答案,我自己的问题。

Ok here i am posting an answer to my own question again.

原来,这一点:

@Html.Raw(Html.GenerateCaptcha("captcha", "white"))
@Html.ValidationMessage("captcha")

被渲染这样的:

<script type="text/javascript" src="http://www.google.com/recaptcha/api/challenge?k=mykey"></script>

script标签的src属性包含HTTP和HTTPS不
因此,要解决这个问题,我只是更换了@ html.raw&安培; @ html.validate与此:

The src attribute of the script tag contained http and not https So, to fix this issue, i just replaced the @html.raw & @html.validate with this:

<script type="text/javascript" src="https://www.google.com/recaptcha/api/challenge?k=mekey"></script>
            <noscript>
                <iframe src="https://www.google.com/recaptcha/api/noscript?k=mykey" height="300" width="500" frameborder="0"></iframe><br>
                <textarea name="recaptcha_challenge_field" rows="3" cols="40"></textarea><input name="recaptcha_response_field" value="manual_challenge" type="hidden" />
            </noscript>

这样做,从得到的错误停止铬调试器。

Doing this stopped chrome debugger from getting the error.

这篇关于C#MVC3:加载网站通过HTTPS无法加载的reCAPTCHA安全code。 Chrome的调试器给出了一个&QUOT;混合内容错误&QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆