Forms authentication timeout event?

Posted on 2004-11-14
Last Modified: 2008-02-01
Is there an event fired when ASP.NET automatically logs a user out when using forms based authentication? I want to do two things at the point that the user's timeout (set in the web.config file) expires:

1) I log user activity in a legacy application which is done fine if they LogOut using the logout button, but I need to also add an audit record if the system logs them out.

2) I would like to re-direct to the login page, rather than the default operation which only redirects when they refresh the page.


Question by:sdj_work
    LVL 6

    Expert Comment

    I dont what you mean by system logging user out. Ok, if you mean you are logging out the user after the session expires, then "Session_End" fires. This event handler is in Global.asax.cs. In this event handler, you can not do any interactions with the browser, as it is fired with a Http request. You can do any other code behind stuff like, writing to a log application.

    There are two ways you can do to redirect the user after certain inactivity. In your html, use  setTimeout setting from javascript to redirect the user. But strictly speaking, client side inactivty does not translate to session inactivity. Session would still gets timed out, even if the user is so active on the browser, but never have to postback in that 20 minutes time (assuming you have the session timeout set to 20 minutes), the session would still timeout. Remember session is a server side object. you can not manipulate it from the client side. But, this is how things are done in real world. Redirect the user after 20 minutes inactivity on the browser



    Author Comment

    That is not the timeout I mean. I appreciate there is a session timeout, but there is also a timeout for the built in Forms Authentication. For my web app the forms authentication expires after 5 minutes to make sure access to any pages is protected. The session timeout is sometime later, say 15 minutes of inactivity, and this tidies up resources. What I'd like to know is: is there an event fired when ASP.NET logs out the authenticated user?
    LVL 20

    Accepted Solution

    Hello sdj_work

    For the question, is there an event fired when ASP.NET logs out the authenticated user?
    The answer is short and simple:
    Alas, there is no event fires when ASP.NET logs out an authenticated user.

    If you need an event to fire, you can use method CacheItemRemovedCallback delegate or define your own class to have a callback method which fires after an interval of time (ASP.NET logs out an authenticated user).

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
    Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
    This video discusses moving either the default database or any database to a new volume.
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    761 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

    12 Experts available now in Live!

    Get 1:1 Help Now