在我的ASP.NET MVC5页面中,我具有超时的单独登录功能。超时过期后,登录页面将在下一个操作中打开,然后继续进行,这样就可以正常工作。只有一个布局问题。如果我在PartialView中单击注销的用户,则登录页面将显示在此PartialView中,而不是整个页面。身份验证代码:
public void OnAuthenticationChallenge(AuthenticationChallengeContext filterContext)
{
if (filterContext.Result == null || filterContext.Result is HttpUnauthorizedResult)
{
filterContext.HttpContext.Session["PlantId"] = filterContext.HttpContext.Request.QueryString["PlantId"];
filterContext.HttpContext.Session["ShowOnlyEnabledRecipes"] = filterContext.HttpContext.Request.QueryString["ShowOnlyEnabledRecipes"];
filterContext.Result = new RedirectResult("~/UserLogin/Login");
}
}
和控制器:
[HttpPost]
public ActionResult Login(LoginModel loginModel)
{
Initialize();
...
return View(loginModel);
}
如何确保登录表单始终占据整个页面?另外,如果通过单击PartialView来调用它?
在部分视图(用于部分视图的控制器)中重定向,结果仅在区域中呈现,如果要定向到另一个页面(URL已更改),则需要在控制器中添加以下代码。您将从Ref链接获得高级信息。
string virtualPath = System.Web.HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority)+ HttpRuntime.AppDomainAppVirtualPath;字符串returnUrl = virtualPath +“ / Home / Index”;return JavaScript(string .Format(“ document.location ='{0}';”,returnUrl));
Ref: http://geekswithblogs.net/DougLampe/archive/2011/08/05/redirecting-from-a-partial-view-the-right-way-in-asp.net.aspx