ASP.NET MVC Session.IsNewSession问题与谷歌浏览 [英] ASP.NET MVC Session.IsNewSession issue with Google Chrome
问题描述
我目前工作的一个会话过期的逻辑块对我的ASP.NET MVC 3.5项目2注销用户,并将其重定向到的AccountController LogOn支持作用。
I'm currently working on a Session expired piece of logic for my ASP.NET 3.5 MVC 2 project to log out a user and redirect them to the AccountController LogOn action.
我有我的所有关心会话状态的行动以下属性,这块code在IE 8的作品,而在Firefox 4或谷歌浏览器10.症状是,当我试图导航到一个用我的[SessionExpireFilter]属性的动作psented视图重新$ p $,在低于code中的ctx.Session.IsNewSession财产评估为真每一次,就算我只有几秒钟到我30-分钟的会议。
I have the following attribute on all my actions that care about session state, and this piece of code works in IE 8, but not Firefox 4 or Google Chrome 10. The symptom is when I attempt to navigate to a view represented by an action with my [SessionExpireFilter] attribute, the ctx.Session.IsNewSession property in the below code is evaluating as "true" every time, even if I'm only seconds into my 30-minute session.
public class SessionExpireFilterAttribute : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
HttpContext ctx = HttpContext.Current;
// check if session is supported
if (ctx.Session != null && ctx.Session.IsNewSession)
{
// If it says it is a new session, but an existing cookie exists, then it must
// have timed out
string sessionCookie = ctx.Request.Headers["Cookie"];
if ((null != sessionCookie) && (sessionCookie.IndexOf("ASP.NET_SessionId") >= 0))
{
FormsAuthentication.SignOut();
ctx.Response.Redirect("~/Account/LogOn");
}
}
base.OnActionExecuting(filterContext);
}
}
有没有办法找出原因Chrome和Firefox都表现这种方式,但IE是不是?先谢谢了。
Is there any way to figure out why Chrome and Firefox are behaving this way, but IE is not? Thanks in advance.
编辑:这是不是在FF工作,我原来想象的。我被引导到了登录动作登录并尝试与我SessionExpireFilter属性来访问一个动作之后。
This is not working in FF as I originally believed. I am being directed to my LogOn action immediately after logging in and attempting to access an action with my SessionExpireFilter attribute.
推荐答案
ASP.NET会为每个请求创建一个新的会话,除非你存储在它的东西。
试着增加code以下到你的的Global.asax
。它工作在我的MVC2和MVC3应用程序具有相同 SessionExpireFilterAttribute
。
ASP.NET will create a new session for every request unless you store something in it.
Try adding the code below to your Global.asax
. It works in my MVC2 and MVC3 apps with the same SessionExpireFilterAttribute
.
protected void Session_Start()
{
Session["Dummy"] = 1;
}
这篇关于ASP.NET MVC Session.IsNewSession问题与谷歌浏览的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!