简体   繁体   English

MVC 5 AspNet身份-值不能为null。 参数名称:来源

[英]MVC 5 AspNet Identity - Value cannot be null. Parameter name: source

I am seeing a very sporadic error when users log into an MVC 5 app. 当用户登录到MVC 5应用程序时,我看到一个非常零星的错误。 It only happens once every 100 or so logins and only happens on a remote web server. 每100次左右的登录仅发生一次,并且仅在远程Web服务器上发生。 When it occurs users cannot login, however, if we recycle the app pool the error goes away and everyone can login again. 发生这种情况时,用户将无法登录,但是,如果我们回收应用程序池,该错误就会消失,所有人都可以再次登录。

Exception information: 
    Exception type: ArgumentNullException 
    Exception message: Value cannot be null.
Parameter name: source
   at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source, Func`2 predicate)
   at ASP._Page_Views_Shared__LoginPartial_cshtml.Execute() in c:\inetpub\wwwroot\appname\Views\Shared\_LoginPartial.cshtml:line 18
   at System.Web.WebPages.WebPageBase.ExecutePageHierarchy()
   at System.Web.Mvc.WebViewPage.ExecutePageHierarchy()
   at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage)
   at System.Web.Mvc.Html.PartialExtensions.Partial(HtmlHelper htmlHelper, String partialViewName, Object model, ViewDataDictionary viewData)
   at ASP._Page_Views_Shared__Layout_cshtml.Execute() in c:\inetpub\wwwroot\appname\Views\Shared\_Layout.cshtml:line 42

According to the above the error occurs in the LoginPartial.cshtml which is from the MVC 5 VS template but I cannot find anything there that would cause this and it doesn't make sense why this happens so sporadically and then recycling the app pool fixes it. 根据上面的内容,该错误发生在MVC 5 VS模板的LoginPartial.cshtml中,但是我在那里找不到任何会导致此错误的原因,并且为什么这种情况如此偶尔发生,然后回收应用程序池来修复,这没有任何意义。

@model POC.Web.Models.LoginViewModel

@{ ViewBag.Title = "Log in"; }

<h2>@ViewBag.Title</h2>
<div class="row">
<div class="col-md-12">
        <section id="loginForm">
            @using (Html.BeginForm("Login", "Account", new { ReturnUrl = ViewBag.ReturnUrl }, FormMethod.Post, new { @class = "form-horizontal", role = "form" }))
            {
                @Html.AntiForgeryToken()
                <hr />
                @Html.ValidationSummary(true)
                <div class="form-group">
                    @Html.LabelFor(m => m.UserName, new {  @class = "col-md-2 control-label" })
                    <div class="col-md-10">
                        @Html.TextBoxFor(m => m.UserName, new { autocomplete = "off", @class = "form-control" })
                        @Html.ValidationMessageFor(m => m.UserName)
                    </div>
                </div>
                <div class="form-group">
                    @Html.LabelFor(m => m.Password, new { @class = "col-md-2 control-label" })
                    <div class="col-md-10">
                        @Html.PasswordFor(m => m.Password, new { @class = "form-control" })
                        @Html.ValidationMessageFor(m => m.Password)
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-md-offset-2 col-md-10">
                        <div class="checkbox">
                            @Html.CheckBoxFor(m => m.RememberMe)
                            @Html.LabelFor(m => m.RememberMe)
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-md-offset-2 col-md-10">
                        <input type="submit" value="Log in" class="btn btn-default" />
                    </div>
                </div>                    
            }
        </section>
    </div>
</div>
@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
}

Found the issue, it was in a different view(LoginPartial) than the above(Login). 发现了问题,它与上面的(登录)视图(登录部分)不同。 Data was null in the cache. 缓存中的数据为空。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM