?
Solved

Notification of Session Expiration

Posted on 2004-09-17
10
Medium Priority
?
1,199 Views
Last Modified: 2012-08-14
I need to accomplish BOTH of the following in my ASP.NET application:

   1.  Notification from ASP.NET that my session is ABOUT to expire.  Session_End notifies you when it HAS expired--I need to know when it's CLOSE to expiring.

   2.  Some way to renew my session for another n minutes, without some cludgy repost-the-page-after-n-minutes solution.

Thanks!

0
Comment
Question by:bryker
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 3
10 Comments
 
LVL 9

Expert Comment

by:hismightiness
ID: 12088039
If you are using Forms Authentication, then use sliding expiration in your Web.Config:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpgenref/html/gngrfforms.asp

<forms name="name"
       loginUrl="url"
       protection="All|None|Encryption|Validation"
       timeout="30"
       path="/"
       requireSSL="true|false"
       slidingExpiration="true|false">
   <credentials passwordFormat="format"/>
</forms>

0
 
LVL 9

Expert Comment

by:hismightiness
ID: 12088053
Sorry, I didn't explain it at all.  I was in too much of a hurry.  The sliding expiration will make the session get extended to the time limit you set every time it receives a request from the authenticated visitor.
0
 
LVL 17

Expert Comment

by:AerosSaga
ID: 12088108
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:bryker
ID: 12103561

The fulfillment of my Session Expiration pipe-dream would be to find the equivalent of this (imaginary) event:

'// Global.asax
Public Sub Session_OnBeforeEnd()

End Sub

Where I could actually DO something about the session expiration.

Is there *anything* like that?

I'm not dismissing your proposal, Saga.  I'm just saying, this would be the ultimate answer to my solution.


0
 

Author Comment

by:bryker
ID: 12263559
I'm looking for a non-third-party tool solution.  Also, mightiness, I'm not using forms authentication.

0
 
LVL 9

Accepted Solution

by:
hismightiness earned 1000 total points
ID: 12264964
bryker,

What you're looking for is something we all cannot wait to have available.  When choosing our method of development for a project (windows forms vs. web forms), this is definitely categorized as one of the "cons" of choosing web forms.  The technology still has not yet advanced to the point of us being able to catch the event you're looking for without a work-around like  what AerosSaga suggested.  

Anyone who builds web applications would certainly benefit from the addition of this even once it becomes available.  Until then, I share your pain and frustration.  

In the meantime, things can be done like having a Session handling class built which checks the session within one of the application request events (i.e., Application_BeginRequest, Application_EndRequest, etc.).  (I must add that this is not the most efficient means.)

I am afraid that the closest thing you can do to get the last few moments prior to a session ending is using a JavaScript timer set to an amount of time just prior to your session ending (Bank of America does this).  Your JavaScript method then can call a page or whatever you find more convenient.

<script language="JavaScript" type="text/javascript">
window.setTimeout("gotoPage()",1000);

function gotoPage(){
     location.href='mypage.aspx';
}
</script>

You can insert this via the RegisterStartUpScript method in your Page_Load event:

      ' Form the script to be registered at client side.
      Dim scriptString As String  = "<script language=""JavaScript"" type=""text/javascript"">" & _
            "window.setTimeout(""gotoPage()"",1000);" & _
            "function gotoPage(){" & _
            "location.href='mypage.aspx';" & _
            "</script>"

      If(Not Me.IsStartupScriptRegistered("Startup")) Then
            Me.RegisterStartupScript("Startup", scriptString)
      End If

This can be done automatically for each page if you create a base page class for your project which inheritis from the System.Web.UI.Page class.  Within this class, you could add the above code to your Page_Load event and have all of your project pages inheriting from this new class.

I hope I didn't confuse you.  This is a long post.
0
 
LVL 9

Expert Comment

by:hismightiness
ID: 12264970
By the way, in this way your session is automatically renewed because a new request is made to the server via the script.
0
 
LVL 9

Expert Comment

by:hismightiness
ID: 12264974
Sorry - one more thing...  My JavaScript example for the timer is only for one second.  You will definitely want to lengthen it (in case you didn't know).
0
 

Author Comment

by:bryker
ID: 12414398
Mighty:

Sorry for the long delay in grading this.  Thanks for your help, and for dumping on my where's-the-magic-bullet parade.

0
 
LVL 9

Expert Comment

by:hismightiness
ID: 12414701
It is my pleasure (for helping, not dumping - hehehe).  I am glad that I can finally help folks instead of always asking for help.  I do what I can to return the favor to the industry that feeds me.  :)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question