当用户登录MVC 5应用程序时,我看到一个非常零星的错误。它每 100 次左右登录仅发生一次,并且仅在远程 Web 服务器上发生。发生这种情况时,用户无法登录,但是,如果我们回收应用程序池,错误就会消失,每个人都可以再次登录。
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:inetpubwwwrootappnameViewsShared_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:inetpubwwwrootappnameViewsShared_Layout.cshtml:line 42
根据上述内容,错误发生在来自 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")
}
发现问题,它与上述视图(登录部分)不同(登录部分)。缓存中的数据为空。