如何将MVC5 RedirectResult()重定向到Asp.net中的整个页面?

如何将MVC5 RedirectResult()重定向到Asp.net中的整个页面?,asp.net,authentication,asp.net-mvc-5,Asp.net,Authentication,Asp.net Mvc 5,在我的ASP.NET MVC5页面中,我有一个带有超时的单独登录功能。这很好,一旦超时过期,登录页面在下一个操作时打开,然后继续。 只有一个布局问题。如果在PartialView中单击已注销的用户,则登录页面将在此PartialView中呈现,而不是在整个页面上呈现。 验证代码: public void OnAuthenticationChallenge(AuthenticationChallengeContext filterContext) { if

在我的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调用它?

在PartialView控制器中执行重定向PartialView,则结果仅在该区域中呈现,如果要指向另一个页面URL更改,则需要在控制器中添加以下代码。您将从Ref链接获得高级信息

p.S.ActionFilter无法返回JavaScript,请放入普通控制器

参考:


请在你的答案中添加一些解释,以便其他人可以从中学习
string virtualPath = System.Web.HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority) + HttpRuntime.AppDomainAppVirtualPath;
string returnUrl = virtualPath + "/UserLogin/Login";
return JavaScript( string .Format( "document.location = '{0}';" , returnUrl));