当用户登录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:\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
根据上面的说法,错误发生在来自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")
}
答案 0 :(得分:1)
发现问题,它是在不同的视图(LoginPartial)而不是上面的(Login)。缓存中的数据为空。