Solved

Notification of Session Expiration

Posted on 2004-09-17
10
1,157 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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

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…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

746 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

13 Experts available now in Live!

Get 1:1 Help Now