Asp.net mvc 如何在ASP.NET MVC中设置跨控制器会话超时以匹配成员身份超时
抱歉,如果可能的话,重复:我一直在寻找,但没有成功 从今天下午开始,我就面临一个问题:问题是我的Asp.net mvc 如何在ASP.NET MVC中设置跨控制器会话超时以匹配成员身份超时,asp.net-mvc,asp.net-mvc-3,session,asp.net-membership,session-timeout,Asp.net Mvc,Asp.net Mvc 3,Session,Asp.net Membership,Session Timeout,抱歉,如果可能的话,重复:我一直在寻找,但没有成功 从今天下午开始,我就面临一个问题:问题是我的BaseController中有一个CrossControllerSession属性,它承载子控制器的会话。我的MVC应用程序的每个控制器都更新/读取此属性 此会话将根据超时时间而过期(请参阅myGlobal.asax和web.config文件)。 出现的情况是,CrossControllerSession有时会在成员身份超时之前超时,这会导致在用户仍处于连接状态时所有变量都为null 有人能告诉我如
BaseController
中有一个CrossControllerSession
属性,它承载子控制器的会话。我的MVC应用程序的每个控制器都更新/读取此属性
此会话将根据超时时间而过期(请参阅myGlobal.asax
和web.config
文件)。
出现的情况是,CrossControllerSession
有时会在成员身份超时之前超时,这会导致在用户仍处于连接状态时所有变量都为null
有人能告诉我如何设置跨控制器会话超时以匹配ASP.NET MVC中的成员超时吗?如果是,请提前感谢您
代码
子控制器
public class MeController : BaseController
{
MonitoringEntitiesDataContext db = new MonitoringEntitiesDataContext();
public ActionResult Provinces(FormsFilter filter,string partial) {
int minId=0;
//Session["UserName"]=User.Identity.Name;
// var session = BaseController.CrossControllerSession;
try
{
string minIdString = BaseController.CrossControllerSession["CodeModule"].ToString();
int.TryParse(minIdString, out minId);
}
catch (Exception)
{
}
var provinces = db.V_STAT_ME_PROVINCEs
.Where(e => e.CodeMinistere == minId);
ViewBag.Session = BaseController.CrossControllerSession;
return View(provinces);
}
protected override void OnActionExecuting(ActionExecutingContext filterContext)
{
BaseController.CrossControllerSession = Session;
base.OnActionExecuting(filterContext);
}
}
Global.asax
protected void Session_End(Object sender, EventArgs e)
{
Session.Clear();
Session.Abandon();
Session.Clear();//lol
}
protected void Session_Start(Object sender, EventArgs e)
{
int timeOut = 1;
try
{
int.TryParse(ConfigurationManager.AppSettings["SessionTimeOut"].ToString(), out timeOut);
}
catch
{ //error logging here
}
Session.Timeout = timeOut;
}
Web.Config
<add key="SessionTimeOut" value="15"/>
亲切的问候 仅使用配置文件解决
Web.config
<authentication mode="Forms">
<forms loginUrl="~/Account/LogOn" timeout="2" slidingExpiration="true" name=".ASPXFORMSAUTH" />
...
</authentication>
...
及
...
此外,我还从Global.asax
文件中删除了Application\u Start
方法
谢谢大家!
<authentication mode="Forms">
<forms loginUrl="~/Account/LogOn" timeout="2" slidingExpiration="true" name=".ASPXFORMSAUTH" />
...
</authentication>
<system.web>
<sessionState
mode="InProc"
cookieless="false"
timeout="2" />
...
</system.web>