My MVC web application uses asp.net session management. Session has default timeout 20mins. On session timeout, user is redirected to the home page. My application uses SessionTimeout ActionFilterAttribute to handle session timeout. SessionState is stored in server.
我的MVC Web应用程序使用asp.net会话管理。会话默认超时20分钟。在会话超时时,用户被重定向到主页。我的应用程序使用SessionTimeout ActionFilterAttribute来处理会话超时。 SessionState存储在服务器中。
Problem: Even if the session timout happens, when the user returns to a particular action method, I need to renew a session for that user and allow to continue instead of redirecting to home page.
问题:即使发生会话时发生,当用户返回特定的操作方法时,我需要为该用户更新会话并允许继续而不是重定向到主页。
I have tried to use the OnActionExecuting method in the SessionTimeout ActionFilterAttribute to identify the session timeout & if the action in the request is that particular action method, then allow the user to continue to that action.
我试图在SessionTimeout ActionFilterAttribute中使用OnActionExecuting方法来识别会话超时,如果请求中的操作是特定的操作方法,则允许用户继续该操作。
But it seems to be not working. It just redirects the user to the Home page. I am not sure how to proceed.
但似乎没有用。它只是将用户重定向到主页。我不知道该怎么办。
2 个解决方案
#1
0
Session have bad problems like timeout and refresh not available, do authentication using forms authentication you can choose this custom authentication sample
会话有超时和刷新不可用等问题,使用表单身份验证进行身份验证可以选择此自定义身份验证示例
Or Else use cookies
或者其他人使用cookies
HttpCookie MyCookie = new HttpCookie("MyCookie");
// for remveing if already Exists adding new;
Request.Cookies.Remove("MyCookie");
if (Request.Cookies["MyCookie"] == null)
{
MyCookie["id"] = id.ToString();
Response.Cookies.Add(MyCookie);
}
else
{
MyCookie["id"] = id.ToString();
// Request.Cookies.Remove("MyCookie");
Response.Cookies.Set(MyCookie);
}
// retries
int id = Convert.ToInt32(Request.Cookies["MyCookie"]["id"]);
#2
0
Thanks for your responses.
谢谢你的回复。
- "Session cannot be renewed" once it has expired.
- Instead of renewing the session, create a new session in the ActionFilters Attribute (SessionTimeout).
一旦过期,“会话无法续订”。
而不是更新会话,在ActionFilters属性(SessionTimeout)中创建一个新会话。
The solution for my problem is to create a new session and re-link it with the domain object/user so that the user can continue his journey. I have done this in my SessionTimeout ActionFilterAttribute, to create new session for only a particular request which has the particular controller/action.
我的问题的解决方案是创建一个新会话并将其与域对象/用户重新链接,以便用户可以继续他的旅程。我在SessionTimeout ActionFilterAttribute中完成了此操作,仅为具有特定控制器/操作的特定请求创建新会话。
#1
0
Session have bad problems like timeout and refresh not available, do authentication using forms authentication you can choose this custom authentication sample
会话有超时和刷新不可用等问题,使用表单身份验证进行身份验证可以选择此自定义身份验证示例
Or Else use cookies
或者其他人使用cookies
HttpCookie MyCookie = new HttpCookie("MyCookie");
// for remveing if already Exists adding new;
Request.Cookies.Remove("MyCookie");
if (Request.Cookies["MyCookie"] == null)
{
MyCookie["id"] = id.ToString();
Response.Cookies.Add(MyCookie);
}
else
{
MyCookie["id"] = id.ToString();
// Request.Cookies.Remove("MyCookie");
Response.Cookies.Set(MyCookie);
}
// retries
int id = Convert.ToInt32(Request.Cookies["MyCookie"]["id"]);
#2
0
Thanks for your responses.
谢谢你的回复。
- "Session cannot be renewed" once it has expired.
- Instead of renewing the session, create a new session in the ActionFilters Attribute (SessionTimeout).
一旦过期,“会话无法续订”。
而不是更新会话,在ActionFilters属性(SessionTimeout)中创建一个新会话。
The solution for my problem is to create a new session and re-link it with the domain object/user so that the user can continue his journey. I have done this in my SessionTimeout ActionFilterAttribute, to create new session for only a particular request which has the particular controller/action.
我的问题的解决方案是创建一个新会话并将其与域对象/用户重新链接,以便用户可以继续他的旅程。我在SessionTimeout ActionFilterAttribute中完成了此操作,仅为具有特定控制器/操作的特定请求创建新会话。