Solved

Notification of Session Expiration

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

 

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

733 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