Asp.net mvc reCaptcha公钥为空

Asp.net mvc reCaptcha公钥为空,asp.net-mvc,recaptcha,Asp.net Mvc,Recaptcha,我有一个错误: System.InvalidOperationException:公钥不能为null或空 “我的控制器”页面“员工/创建”看起来像: @using System.Collections @using System.Collections.Concurrent @using System.Data.SqlTypes @using DataAccess @using Recaptcha.Web.Mvc @using Recaptcha.Web; @using Recaptcha.We

我有一个错误:

System.InvalidOperationException:公钥不能为null或空

“我的控制器”页面“员工/创建”看起来像:

@using System.Collections
@using System.Collections.Concurrent
@using System.Data.SqlTypes
@using DataAccess
@using Recaptcha.Web.Mvc
@using Recaptcha.Web;
@using Recaptcha.Web.Mvc;
@model DataAccess.Employee

@{
ViewBag.Title = "Create";
}
@{ Layout = "/views/shared/_EmployeeLayout.cshtml";
}


@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}

@using (Html.BeginForm())
{
@Html.AntiForgeryToken()

<div class="container">
    <h2>Please, provide some information.</h2>
    <div class="row">
        <div class="col-md-8">
            <div class="form-group">
                @Html.LabelFor(model => model.Name, "Name", htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.EditorFor(model => model.Name, new { htmlAttributes = new { @class = "form-control" } })
                    @Html.ValidationMessageFor(model => model.Name, "", new { @class = "text-danger" })
                </div>
            </div>
            <br />
            <br />
            <div class="form-group">
                @Html.LabelFor(model => model.Surname, "Surname", htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.EditorFor(model => model.Surname, new { htmlAttributes = new { @class = "form-control" } })
                    @Html.ValidationMessageFor(model => model.Surname, "", new { @class = "text-danger" })
                </div>
            </div>
            <br />
            <br />
            <div class="form-group">
                @Html.LabelFor(model => model.Location, "Location", htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">

                    @Html.DropDownList("LocationID", null, "--Please pick one--", new { @class = "form-control" })
                    @Html.ValidationMessageFor(model => model.Location, "", new { @class = "text-danger" })
                </div>
            </div>
            <br />
            <br />

            <div class="form-group">
                @Html.LabelFor(model => model.Mail, "E-mail", htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.EditorFor(model => model.Mail, new { htmlAttributes = new { @class = "form-control" } })
                    @Html.ValidationMessageFor(model => model.Mail, "", new { @class = "text-danger" })
                </div>
            </div>
            <br />
            <br />
            <div class="form-group">
                @Html.LabelFor(model => model.Telephone, "Telephone number", htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.EditorFor(model => model.Telephone, new { htmlAttributes = new { @class = "form-control" } })
                    @Html.ValidationMessageFor(model => model.Telephone, "", new { @class = "text-danger" })
                </div>
            </div>
            <br />
            <br />
            <div class="form-group">
                @Html.LabelFor(model => model.EnglishLang.NameLang, "English level", htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.DropDownList("EngID", null, "--Choose level--", new { @class = "form-control" })
                    @Html.ValidationMessageFor(model => model.EngID, "", new { @class = "text-danger" })
                </div>
            </div>

            <br />
            <br />
            <div class="form-group">
                @Html.LabelFor(model => model.Faculty.FacultyName, "Faculty", htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.DropDownList("FacultyID", null, "Choose a faculty", new { @class = "form-control" })
                    @Html.ValidationMessageFor(model => model.FacultyID, "", new { @class = "text-danger" })
                </div>
            </div>
            <br />
            <br />
            <div class="form-group">
                @Html.LabelFor(model => model.StartEduYear, "Entrance study year", htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.DropDownListFor(model => model.StartEduYear, ViewBag.StartYearFaculty as IEnumerable<SelectListItem>)
                    @Html.ValidationMessageFor(model => model.StartEduYear, "", new { @class = "text-danger" })
                </div>
            </div>
            <br />
            <br />
            <div class="form-group">
                @Html.LabelFor(model => model.AvgScore, "Average score", htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.DropDownListFor(model => model.AvgScore, ViewBag.AverScore as IEnumerable<SelectListItem>)
                    @Html.ValidationMessageFor(model => model.AvgScore, "", new { @class = "text-danger" })
                </div>
            </div>
            <br />
            <br />

            <div class="form-group">
                @Html.LabelFor(model => model.GradYear, "Graduation year", htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.DropDownListFor(model => model.GradYear, ViewBag.GradYear as IEnumerable<SelectListItem>)
                    @Html.ValidationMessageFor(model => model.GradYear, "", new { @class = "text-danger" })
                </div>
            </div>
            <p></p>
            <br />
            <br />
            <p></p>
            <p></p>


            <div class="form-group">
                @Html.LabelFor(model => model.WExp, "Work Experience", htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.TextAreaFor(model => model.WExp, new { @class = "form-control" })
                    @Html.ValidationMessageFor(model => model.WExp, "", new { @class = "text-danger" })
                </div>
            </div>
            <p></p>
            <br />
            <br />
            <br />
            <div class="form-group">
                @Html.LabelFor(model => model.Interests, "Interests", htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.TextAreaFor(model => model.Interests, new { @class = "form-control" })
                    @Html.ValidationMessageFor(model => model.Interests, "", new { @class = "text-danger" })
                </div>
            </div>
            <p></p>

            <span>Did you have any additional trainings?</span>
            <label for="chkYes">
                <input type="radio" id="chkYes" name="chkPassPort" onclick=" ShowHideDiv() " />Yes
            </label>
            <label for="chkNo">
                <input type="radio" id="chkNo" name="chkPassPort" onclick=" ShowHideDiv() " />No
            </label>

            <div class="form-group" id="dvPassport" style="display: none">
                @Html.LabelFor(model => model.Trainings, "Trainings", htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.TextAreaFor(model => model.Trainings, new { @class = "form-control" })
                    @Html.ValidationMessageFor(model => model.Trainings, "", new { @class = "text-danger" })
                </div>
            </div>
            <p></p>
            <span>Did you have any projects recently?</span>
            <label for="chkYes">
                <input type="radio" id="chkYes1" name="chkPassPort1" onclick=" ShowHideDiv() " />Yes
            </label>
            <label for="chkNo">
                <input type="radio" id="chkNo1" name="chkPassPort1" onclick=" ShowHideDiv() " />No
            </label>

            <div class="form-group" id="dvExample" style="display: none">
                @Html.LabelFor(model => model.Projects, "Projects", htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.TextAreaFor(model => model.Projects, new { @class = "form-control" })
                    @Html.ValidationMessageFor(model => model.Projects, "", new { @class = "text-danger" })
                </div>
            </div>
            <p></p>
            <span>Have you been in some students organization?</span>
            <label for="chkYes">
                <input type="radio" id="chkYes2" name="chkPassPort2" onclick=" ShowHideDiv() " />Yes
            </label>
            <label for="chkNo">
                <input type="radio" id="chkNo2" name="chkPassPort2" onclick=" ShowHideDiv() " />No
            </label>

            <div class="form-group" id="dvExample1" style="display: none">
                @Html.LabelFor(model => model.StudOrg, "Organizations", htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.TextAreaFor(model => model.StudOrg, new { @class = "form-control" })
                    @Html.ValidationMessageFor(model => model.StudOrg, "", new { @class = "text-danger" })
                </div>
            </div>
        </div>
        <div class="form-group">
            <div class="g-recaptcha" data-sitekey="6LccVRcTAAAAADLo_LxSj4mQzt9jLrgbo5L9wZ-J"></div>
            <div>
                @if (TempData["recaptcha"] != null)
                {
                    <p>@TempData["recaptcha"]</p>
                }
            </div>
        </div>
        <br />
        <br />
        <div class="col-md-offset-2 col-md-10">

            <b></b>
            <div class="form-group">
                @Html.Recaptcha()
            </div>

            <br />
            <br />
            <br />
            <br />
            <input type="submit" value="Apply" class="btn btn-default" style="text-align: center" />
        </div>
    </div>
    <p></p>

</div>
}

  <script type="text/javascript">
    function ShowHideDiv() {
    var chkYes = document.getElementById("chkYes");
    var chkYes1 = document.getElementById("chkYes1");
    var chkYes2 = document.getElementById("chkYes2");

    var dvPassport = document.getElementById("dvPassport");
    var dvExample = document.getElementById("dvExample");
    var dvExample1 = document.getElementById("dvExample1");

    dvPassport.style.display = chkYes.checked ? "block" : "none";
    dvExample.style.display = chkYes1.checked ? "block" : "none";
    dvExample1.style.display = chkYes2.checked ? "block" : "none";

}

因为这个错误,我快发疯了,这是网络上的某个人实现的,但我再也找不到了(我已经重新安装了操作系统)…如果你能帮我弄清楚,那就太棒了

如果您刚刚更新了nuget软件包,请在appSettings部分的末尾查找重复的设置初始化,如下所示:

  <add key="recaptchaPublicKey" value="" /><add key="recaptchaPrivateKey" value="" /><add key="recaptchaApiVersion" value="1" />

  <add key="recaptchaPublicKey" value="" /><add key="recaptchaPrivateKey" value="" /><add key="recaptchaApiVersion" value="1" />