Detect ASP.NET Session Timeout - ASP.NET_SessionId method not working -
i'm trying detect asp.net session timeout redirect user timeout page; i've checked various methods, of them similar to
http://aspalliance.com/520_detecting_aspnet_session_timeouts.2
(if session.isnewsession , asp.net_sessionid cookie exists, timeout)
the problem "asp.net_sessionid" cookie present me, if started debugging, giving me false timeout flag when starting web site first time.
update: testing, i've created empty asp.net web application following codes:
basepage.cs
using system; using system.web.ui; namespace testapp.classes { public class basepage : page { protected override void oninit(eventargs e) { base.oninit(e); if (context.session != null) { if (session.isnewsession) { string szcookieheader = request.headers["cookie"]; if ((null != szcookieheader) && (szcookieheader.indexof("asp.net_sessionid") >= 0)) { response.redirect("sessiontimeout.htm"); } } } } } } global.asax
using system; namespace testapp { public class global : system.web.httpapplication { protected void application_start(object sender, eventargs e) { } protected void session_start(object sender, eventargs e) { var = ""; } protected void application_beginrequest(object sender, eventargs e) { } protected void application_authenticaterequest(object sender, eventargs e) { } protected void application_error(object sender, eventargs e) { } protected void session_end(object sender, eventargs e) { var b = ""; } protected void application_end(object sender, eventargs e) { } } } webform1.aspx
using system; using testapp.classes; namespace testapp { public partial class webform1 : basepage { protected void page_load(object sender, eventargs e) { } } } web.config
<?xml version="1.0"?> <configuration> <system.web> <compilation debug="true" targetframework="4.5" /> <httpruntime targetframework="4.5" /> <sessionstate timeout="1"></sessionstate> </system.web> </configuration> then hit f5, , redirected sessiontimeout.htm. why?
you don't have use cookie when develop website. there other ways store data, e.g. can store data specific user in database
note "cookieless = false" attrubute of sessionstate element in web.config means sessionid of current session saved in client machine cookie
<sessionstate cookieless="true" /> default settings asp.net session state defined in machine.config file , can overridden in web.config file in application's root folder. ensuring above line appears in root web.config file, enable cookieless sessions
refer http://msdn.microsoft.com/en-us/library/aa479314.aspx
so check session.isnewsession , disable cookie
Comments
Post a Comment