Hi Folks, I read an article online to keep the session alive as long as your website is opne on browser. That article instructs to use IFRAME on master page. Link this IFRAME to keepAlive.aspx page. Then write this code to head tag of keepAlive.aspx
the meta frefresh element will automatically call the provided url.
The code in the code behind sets the meta element to a specific amount of minutes. Hence the Timeout * 60 to get it in seconds and the - 60 to subtract one minute (60 seconds).
The ?q = ... Ticks is used to make the querystring unique as otherwise the browser might not want to request it as it's always the same url and makes use of the cached version it has.
Grz, Kris.
Read my blog | Twitter Interested in Azure, ASP.NET (MVC), jQuery, WCF, EF, MS SQL, ...
Keep the forums clean: report to the moderation team!
Thanks for the explaination. That means the page_load code is overriding content value of the following line which was defined in the head section of keppAlive.asp. Is that what is doing?
If it is overriding the content value than I can put any number in the above line and this does not need to be 21600 which is 6 hours. All I want from the code is to to renew my session 60 seconds before it expires. I have set session timeout=20 minutes
in web.config
Now when I try the above mentioned mehod or simply iframe in site.master. The application freezes when loading the login.aspx. I see many login.aspx?ReturnUrl=/KeepSessionAlive.aspx instances under the internet explorer in solution explorer. I dont know
whats going on.
as the iframe works as a sandboxed version that iframed page likely didn't get authenticated. You can either exclude it from the to be authenticated pages or make use of ajax on your master page to "ping" a specific page or controller in case of MVC. Either
way your page needs to be publicly available without the need to be logged in to view it.
Grz, Kris.
Read my blog | Twitter Interested in Azure, ASP.NET (MVC), jQuery, WCF, EF, MS SQL, ...
Keep the forums clean: report to the moderation team!
Marked as answer by shanewatz on Dec 24, 2012 12:20 PM
shanewatz
Member
11 Points
30 Posts
Looking for some code explaination
Dec 23, 2012 03:21 PM|LINK
Hi Folks, I read an article online to keep the session alive as long as your website is opne on browser. That article instructs to use IFRAME on master page. Link this IFRAME to keepAlive.aspx page. Then write this code to head tag of keepAlive.aspx
<meta id="MetaRefresh" http-equiv="refresh" content="21600;url=KeepSessionAlive.aspx" runat="server" />
Then write this code on keepAlive.aspx page load event.
Protected Sub Page_Load(sender As Object, e As EventArgs)
If User.Identity.IsAuthenticated Then
' Refresh this page 60 seconds before session timeout, effectively resetting the session timeout counter.
MetaRefresh.Attributes("content") = Convert.ToString((Session.Timeout * 60) - 60) + ";url=KeepSessionAlive.aspx?q=" + DateTime.Now.Ticks
End If
End Sub
I would like to get some explaination on this code. What this code is doing? Pleae explain this line
MetaRefresh.Attributes("content") = Convert.ToString((Session.Timeout * 60) - 60) + ";url=KeepSessionAlive.aspx?q=" + DateTime.Now.Ticks
Please help me with this. I will highly appreciate your kind help.
Regards,
XIII
All-Star
182702 Points
23463 Posts
ASPInsiders
Moderator
MVP
Re: Looking for some code explaination
Dec 23, 2012 03:26 PM|LINK
Hi,
the meta frefresh element will automatically call the provided url.
The code in the code behind sets the meta element to a specific amount of minutes. Hence the Timeout * 60 to get it in seconds and the - 60 to subtract one minute (60 seconds).
The ?q = ... Ticks is used to make the querystring unique as otherwise the browser might not want to request it as it's always the same url and makes use of the cached version it has.
Grz, Kris.
Interested in Azure, ASP.NET (MVC), jQuery, WCF, EF, MS SQL, ...
Keep the forums clean: report to the moderation team!
shanewatz
Member
11 Points
30 Posts
Re: Looking for some code explaination
Dec 23, 2012 03:40 PM|LINK
Thanks for the explaination. That means the page_load code is overriding content value of the following line which was defined in the head section of keppAlive.asp. Is that what is doing?
<meta id="MetaRefresh" http-equiv="refresh" content="21600;url=KeepSessionAlive.aspx" runat="server" />
If it is overriding the content value than I can put any number in the above line and this does not need to be 21600 which is 6 hours. All I want from the code is to to renew my session 60 seconds before it expires. I have set session timeout=20 minutes in web.config
Thanks
XIII
All-Star
182702 Points
23463 Posts
ASPInsiders
Moderator
MVP
Re: Looking for some code explaination
Dec 23, 2012 04:11 PM|LINK
Hi,
likely it's put in there just to keep validation warnings away but indeed, in the code it gets overwritten.
Grz, Kris.
Interested in Azure, ASP.NET (MVC), jQuery, WCF, EF, MS SQL, ...
Keep the forums clean: report to the moderation team!
shanewatz
Member
11 Points
30 Posts
Re: Looking for some code explaination
Dec 23, 2012 04:24 PM|LINK
Thanks Kris, appreciate your help.
shanewatz
Member
11 Points
30 Posts
Re: Looking for some code explaination
Dec 24, 2012 12:32 AM|LINK
Now when I try the above mentioned mehod or simply iframe in site.master. The application freezes when loading the login.aspx. I see many login.aspx?ReturnUrl=/KeepSessionAlive.aspx instances under the internet explorer in solution explorer. I dont know whats going on.
Please help.
XIII
All-Star
182702 Points
23463 Posts
ASPInsiders
Moderator
MVP
Re: Looking for some code explaination
Dec 24, 2012 08:01 AM|LINK
Hi,
as the iframe works as a sandboxed version that iframed page likely didn't get authenticated. You can either exclude it from the to be authenticated pages or make use of ajax on your master page to "ping" a specific page or controller in case of MVC. Either way your page needs to be publicly available without the need to be logged in to view it.
Grz, Kris.
Interested in Azure, ASP.NET (MVC), jQuery, WCF, EF, MS SQL, ...
Keep the forums clean: report to the moderation team!
shanewatz
Member
11 Points
30 Posts
Re: Looking for some code explaination
Dec 24, 2012 12:20 PM|LINK
Thanks Kris, That works like a charm.
Cheers,