我的Html.Action()之一出现了StackOverflowException异常,只有在调试Web服务器实例并停止响应后才会捕获到异常。收到的错误如下所示:
System.StackOverflowException was unhandled
Cannot evaluate expression because the current thread is in a stack overflow state.
引发异常的行是这样的:
<div id="userInfoSummary">@Html.Action("Summary", "User")</div>
这发生在我登录,然后被重定向到主页时(但由于它被卡住而从未发生)。
以下是我检查用户是否已登录以正确呈现视图的方式:
<div id="userPanel">
@if (!SessionManager.CheckSession(SessionKeys.User))
{
<div id="loginForm">@Html.Action("Login", "User")</div>
<div id="registerForm">@Html.Action("Register", "User")</div>
<hr class="greyLine" />
<div id="recentlyViewedItems">
<div id="recentItemsTitle">
<span class="recentItemsIcon"></span><span class="theRecentTitle">Recently Viewed</span>
</div>
</div>
}
else
{
<div id="userInfoSummary">@Html.Action("Summary", "User")</div>
}
</div>
这里是我的Action方法:
[HttpPost]
public ActionResult Login(LoginViewModel dto)
{
bool flag = false;
if (ModelState.IsValid)
{
if (_userService.AuthenticateUser(dto.Email, dto.Password, false)) {
var user = _userService.GetUserByEmail(dto.Email);
var uSession = new UserSession
{
ID = user.Id,
Nickname = user.Nickname
};
SessionManager.RegisterSession(SessionKeys.User, uSession);
flag = true;
}
}
if (flag)
return RedirectToAction("Index", "Home");
else
{
ViewData.Add("InvalidLogin", "The login info you provided were incorrect.");
return View(dto);
}
}
public ActionResult Summary()
{
var user = _helper.GetUserFromSession();
var viewModel = Mapper.Map<User, UserInfoSummaryViewModel>(user);
return View(viewModel);
}
我如何获取有关此异常的更多信息?为什么首先会发生这种情况?我不认为有任何无限循环或无限循环的递归函数...难道是因为我同时调用了几个Html.Action()方法吗?
return PartialView(viewModel);
,@{ Layout = null; }
。这段代码在我的电脑上运行没有问题,但是发布后就出现了问题。 我还有其他的@Html.Actions
也没有任何问题。 - JonathanPeelChildActionOnly
。 - JonathanPeel