【发布时间】:2013-11-08 00:34:28
【问题描述】:
我有一个 _LayoutView:
@{
Layout = "~/Views/Shared/_NavLayout.cshtml";
}
@section styles
{
@RenderSection("styles", required: false)
}
<div class="container" style="padding-top: 60px;">
<div class="row">
<div class="col-md-12">
@Html.Action("AccountNavigation")
</div>
</div>
@RenderSection("InlineTitle", required:false)
@RenderBody()
</div>
@section scripts {
@Scripts.Render("~/bundles/jqueryval")
@RenderSection("scripts", required: false)
}
如果我删除它会很好
@Html.Action("AccountNavigation")
否则我会得到:
动作方法是:
[ChildActionOnly]
public ActionResult AccountNavigation()
{
var roles = UserManager.GetRoles(User.Identity.GetUserId());
ViewBag.IsAdmin = roles.Contains("Admin");
return PartialView("_AccountNavigatorPartial");
}
我尝试将其剥离为:
[ChildActionOnly]
public ActionResult AccountNavigation()
{
ViewBag.IsAdmin = false;
return null;
}
但这并没有什么区别。
使用该布局的子视图之一是 Login。
[AllowAnonymous]
public ActionResult Login(string returnUrl)
{
ViewBag.OidLoginFailed = false;
ViewBag.ReturnUrl = returnUrl;
return View();
}
如果我在其中放置一个中断点,我可以看到它在每个请求中被多次调用并建立 ReturnUrl 直到它失败,因此出现错误消息。这就是我剥离 AccountNavigation ActionMethod 的原因。
我认为可能是 anon 请求通过一些配置设置导致回发,如果 Anon 重定向到 Login 并循环它会去,但我看不到触发的位置。
帐户 _AccountNavigatorPartial 只是:
<ul class="nav navbar-nav navbar-Left">
<li>@Html.ActionLink("Manage Credentials", "Credentials", "Account",
routeValues: null, htmlAttributes: new { id = "credentialsLink" })</li>
<li>@Html.ActionLink("Manage Profile", "Profile", "Account",
routeValues: null, htmlAttributes: new { id = "credentialsLink" })</li>
</ul>
所以我要做的就是注入一些用于帐户导航的 html。我正在使用 ASP.Identity 作为成员资格,但我看不出这有什么不同,因为我正在请求一个匿名可访问页面。
【问题讨论】:
-
我不确定你在问什么,因为它与我的问题有关?登录视图有一个回发的表单,但我什至无法呈现初始 GET 来回发。上面的 GET 就是这样,当表单被提交时,它正在发布。但如上所述,我不确定我是否明白你的意思?
标签: c# asp.net asp.net-mvc-4 asp.net-identity