Solved

Notification of Session Expiration

Posted on 2004-09-17
10
1,164 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
  • 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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 9

Accepted Solution

by:
hismightiness earned 250 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
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…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

863 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now