简体   繁体   English

刷新时,asp.net mvc中的会话超时

[英]session timeout in asp.net mvc when refresh

I am running an ASP.NET 4.0 application and published it using plesk control panel.I have done the following. 我正在运行ASP.NET 4.0应用程序,并使用plesk控制面板发布了它。

1.i set session timeout in web.config file as: 1.i在web.config文件中将会话超时设置为:

<sessionState timeout="20000"/>
  1. I handled session variable in login controller like this: 我在登录控制器中像这样处理会话变量:

Session["userId"] = lUser.userId; Session["role"] = lUser.userType;

into other controller, the code is like below: 进入其他控制器,代码如下:

if (Session["role"] == null)
{
     return RedirectToAction("Index", "Login");
}
 else if (Session["role"].ToString() == "Admin" || Session["role"].ToString() == "Super Admin")
{
    return View();
}

this code is ok in my local server but when published into real server using plesk control panel, it also ok for first time. 此代码在我的本地服务器中是可以的,但是当使用plesk控制面板将其发布到真实服务器中时,这也是第一次。 but when i click the same menu second time it redirects to login page. 但是,当我第二次单击相同的菜单时,它将重定向到登录页面。

Try adding: 尝试添加:

protected void Session_Start(Object sender, EventArgs e)
{
    Session["init"] = 0;
}

to global.asax 到global.asax

可以使用SessionState Mode =“ StateServer”代替SessionState mode =“ InProc”,但是您需要确保要在其中驻留应用程序的服务器具有激活的StateServer。

<sessionState mode="StateServer" timeout="20000" cookieless="false" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM