Solved

Notification of Session Expiration

Posted on 2004-09-17
10
1,194 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
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 

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 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

695 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