【发布时间】:2017-11-02 20:41:57
【问题描述】:
这里是 MVC 菜鸟。
我目前有这段代码在通过 AJAX 加载页面时触发我的 HomeController:
namespace ETTData.Controllers
{
public class HomeController : Controller
{
[HttpPost]
public ContentResult clearSessions()
{
var currentSession = System.Web.HttpContext.Current.Session;
System.Diagnostics.Debug.WriteLine("BEFORE: " + currentSession.Timeout);
currentSession.Abandon();
//currentSession.RemoveAll();
//currentSession.Clear();
System.Diagnostics.Debug.WriteLine("AFTER : " + currentSession.Timeout);
return new ContentResult { Content = "OK", ContentType = "text/plain" };
}
}
}
debug.WriteLine的输出是:
之前:35
之后:35
如您所见,它在 BEFORE 上有 35,但在 AFTER 时也有 35它不应该等于任何东西,因为我在调用该输出之前使用了 currentSession.Abandon();。
我正在通过 Global.asax.cs 文件设置会话超时:
namespace ETTData
{
public class MvcApplication : System.Web.HttpApplication
{
protected void Session_Start(Object sender, EventArgs e)
{
HttpContext.Current.Session.Timeout = 35;
}
}
}
这么说 - 我不知道为什么它不清除会话......
【问题讨论】:
标签: c# asp.net asp.net-mvc model-view-controller asp.net-mvc-5