Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 会话过期时将部分视图重定向到登录页面_Asp.net_Asp.net Mvc_Session_Asp.net Mvc Partialview - Fatal编程技术网

Asp.net 会话过期时将部分视图重定向到登录页面

Asp.net 会话过期时将部分视图重定向到登录页面,asp.net,asp.net-mvc,session,asp.net-mvc-partialview,Asp.net,Asp.net Mvc,Session,Asp.net Mvc Partialview,会话过期后,是否有简单的方法将整个页面(而不仅仅是部分视图)重定向到登录页面 我尝试了以下解决方案,但无法使其工作: 我的问题是部分视图重定向到登录页面,而不是整个页面(与链接中的问题相同) 控制器 [HttpPost] public PartialViewResult LogPartialView(string a, int? b, string c, string d, int? e, string f) { /

会话过期后,是否有简单的方法将整个页面(而不仅仅是部分视图)重定向到登录页面

我尝试了以下解决方案,但无法使其工作:

我的问题是部分视图重定向到登录页面,而不是整个页面(与链接中的问题相同)

控制器

        [HttpPost]
        public PartialViewResult LogPartialView(string a, int? b, string c, string d, int? e, string f)
        {
            //If the user is "Admin" -> display Logs for all customers.
            if (Roles.IsUserInRole(WebSecurity.CurrentUserName, "Admin"))
            {
                if (Session["myID"] == null)
                {
                    ExpireSession();
                }
            //Some code

        return PartialView("LogPartialLayout", model);
        }
如果myID为null,我想返回Redirect(~/),但它不起作用,因为它需要一个局部视图

错误消息:无法将类型“System.Web.Mvc.RedirectResult”隐式转换为“System.Web.Mvc.PartialViewResult”

public void ExpireSession()
    {
        Session.Abandon();
        WebSecurity.Logout();
        Response.Redirect("~/");

    }
网络配置

<authentication mode="Forms">
  <forms loginUrl="~/Account/RedirectToLogin" timeout="2880" />
</authentication>
_重定向到登录视图

<script>
    window.location = '@Url.Action("Login", "Account")';
</script>

window.location='@Url.Action(“登录”、“帐户”);

诸如此类,相应地更改URL

我将基于@EmilChirambattu的答案

[HttpPost]
public ActionResult LogPartialView(string a, int? b, string c, string d, int? e, string f)
{
    // You should check the session before anything else.
    if (Session["myID"] == null)
    {
        return ExpireSession();
    }

    //If the user is "Admin" -> display Logs for all customers.
    if (Roles.IsUserInRole(WebSecurity.CurrentUserName, "Admin"))
    {
        //Some code
    }

    return PartialView("LogPartialLayout", model);
}

public void ExpireSession()
{
    Session.Abandon();
    WebSecurity.Logout();
    Response.Redirect("RedirectToLogin");
}

public ActionResult RedirectToLogin()
{
    return PartialView("_RedirectToLogin");
}
\u重定向到登录视图

<script>
    window.location = '@Url.Action("Index", "")';
</script>

window.location='@Url.Action(“索引”,“索引”);

这会将您重定向到页面的基本URL(很可能是您的登录页面)。

将方法的签名更改为:
public ActionResult LogPartialView(…)
@haim770 I added if session=null->redirect(~/”)但它仍然在局部视图中重定向。@haim770..我忘了提到我已更改为public ActionResult,但没有成功。仍然在PartialView中重定向。
<script>
    window.location = '@Url.Action("Index", "")';
</script>