The ASP.NET HttpSessionState class provides a useful IsNewSession( ) method that returns true if a new session was created for this request. The key to detecting a session timeout is to also look for the ASP.NET_SessionId cookie
in the request. If this is a new session but the cookie is present, this indicates a timeout situation. In order to implement this effectively for an entire web site, it is useful to utilize the “Base Page” concept described in a
what assemblies do you have to include for this code to work? I tried:
using System.Web;
using
System.Web.SessionState;
without success.
(edit: Error 363 An object reference is required for the non-static field, method, or property 'System.Web.HttpContext.Session.get' myproject\Controllers\HomeController.cs ...
when i am opening the page in one system is working fine
at the same time u open the same page in another system, the values in the variables of the page are changing according to the changes done in another system if i made changes then the changed values r reflected in another system too
might be both are working on same session even though they r on two different system
coderocks
Member
5 Points
4 Posts
Session State
Mar 28, 2008 04:14 PM|LINK
I am new to the whole MVC approach to web development.
How do you keep session state for a user, on the server, between http posts.
Examples: Login/Logout, Shopping cart content, etc.
stateserver session state
tumickey
Member
10 Points
9 Posts
Re: Session State
Mar 28, 2008 05:19 PM|LINK
in controller use session
HttpSessionStateBase session = HttpContext.Session;
i have ex:
create login controller
public void Login(string id){
HttpSessionStateBase session = HttpContext.Session;
// check username , pass .
if(checkuser(){
session["login"] = true ;
....
}
create check login
public bool CheckLogin()
{
HttpSessionStateBase session = HttpContext.Session;
if (session["Login"] == null)
{
return false;
}
else
{
return (bool)session["Login"];
}
}
}
...
:)
session
coderocks
Member
5 Points
4 Posts
Re: Session State
Mar 28, 2008 08:14 PM|LINK
Is this session lifetime controlled the same as forms based asp.net apps.
I tried setting the timeout to 1, but the state seemed to persist beyond 1 minute.
Also, I couldn't find an event to catch or hook to know when the session has timed out. (i.e. to allow for a redirect)
Thanks
tumickey
Member
10 Points
9 Posts
Re: Session State
Mar 29, 2008 02:50 AM|LINK
http://msdn2.microsoft.com/en-us/library/ms972429.aspx
The ASP.NET HttpSessionState class provides a useful IsNewSession( ) method that returns true if a new session was created for this request. The key to detecting a session timeout is to also look for the ASP.NET_SessionId cookie in the request. If this is a new session but the cookie is present, this indicates a timeout situation. In order to implement this effectively for an entire web site, it is useful to utilize the “Base Page” concept described in a
http://aspalliance.com/520_Detecting_ASPNET_Session_Timeouts.2
http://www.webmonkey.com/webmonkey/03/30/index3a.html?tw=programming
Fun.
ralgomes
Member
2 Points
3 Posts
Re: Session State
Apr 15, 2008 11:43 PM|LINK
what assemblies do you have to include for this code to work? I tried:
using System.Web;
using
System.Web.SessionState;without success.
(edit: Error 363 An object reference is required for the non-static field, method, or property 'System.Web.HttpContext.Session.get' myproject\Controllers\HomeController.cs ...
ykng
Member
3 Points
13 Posts
Re: Session State
Apr 16, 2008 11:27 AM|LINK
Have you tried HttpContext.Current.Session ?
dkl
Member
44 Points
26 Posts
Re: Session State
Apr 16, 2008 01:17 PM|LINK
Do not use this - it is not possible to mock it in tests.
You usually need to write something like this in your Controller tests:
HttpContextBase httpContext = (HttpContextBase)_mocks.CreateMock(typeof(HttpContextBase));HttpSessionStateBase session = (HttpSessionStateBase)_mocks.CreateMock(typeof(HttpSessionStateBase));
ControllerContext cc = new ControllerContext(httpContext, new RouteData(), c);
yourController.ControllerContext = cc;
kvk5433
Member
10 Points
5 Posts
Re: Session State
Jun 24, 2008 06:06 AM|LINK
Hi All
I am working an web application in asp.net 2.0
when i am opening the page in one system is working fine
at the same time u open the same page in another system, the values in the variables of the page are changing according to the changes done in another system if i made changes then the changed values r reflected in another system too
might be both are working on same session even though they r on two different system
can any one can sort this outThanks in Advance